[Tips & Tricks] Script to append field values

[Tips & Tricks] Script to append field values

Scenario:

One of our customers had come up with a requirement to capture a date type of additional field value to the subject of the request. This would make his work easy rather than updating it manually. He preferred to capture only the date (without the time value) to have the subject content look better.

Head to this article to learn about the field and form rules.

Solution:

His requirement was accomplished through Field and Form Rules Javascript.

                                                            

Here is the script,

To display the month value in string format,

var sub=$CS.getValue("SUBJECT");
var d = $CS.getValue("WorkOrder_Fields_UDF_DATE3");
var month_abre_name =['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var nd = d.getFullYear()+"-"+month_abre_name[d.getMonth()]+"-"+d.getDate();
var new_sub = sub + ' has been scheduled for ' + nd;
if($CS.isFormSubmit()){  $CS.setValue("SUBJECT", new_sub);


                                                
                                                      


To display the month value in numerical format,

var sub=$CS.getValue("SUBJECT");
var d = $CS.getValue("WorkOrder_Fields_UDF_DATE3");
var mon = d.getMonth()+1;
var nd = d.getFullYear()+"-"+mon+"-"+d.getDate();
var new_sub = sub + ' has been scheduled for ' + nd;
if($CS.isFormSubmit()){  $CS.setValue("SUBJECT", new_sub);


                                                            


Similarly, if you would like to capture the value to the request description, make use of the below script.

var desc=$CS.getValue("DESCRIPTION");
var d = $CS.getValue("WorkOrder_Fields_UDF_DATE3");
var mon = d.getMonth()+1;
var nd = d.getFullYear()+"-"+mon+"-"+d.getDate();
var new_desc = desc + ' has been scheduled for ' + nd;
if($CS.isFormSubmit()){  $CS.setValue("DESCRIPTION", new_desc);


NOTE: I have highlighted the script for the convenience for modifying date format and separator and subject content as required.

Though this is a simple script, this would help save a lot of time. I hope you find this post useful. Cheers..!


                New to ADManager Plus?

                  New to ADSelfService Plus?