Service Catalog Client Script to Copy Reference field value to a String field value

Su522
Kilo Sage

Need some help please…

I have a Service Catalog Item for a Company Name Change

1 variable is a Reference field to the Old Company Name [core_company] named: old_name

1 variable is a Single Line Text field named: old_name_hist

I need to Copy the value of the Reference field ‘old_name’ to a String to put it in the Single Line Text field ‘old_name_hist’

This is so when the old company name is renamed in ServiceNow, the Single Line Text field variable for the associated SCTASKs retain the historical data of the old Company Name, so multiple teams can process the request and know the old Company Name.

 

I have a Service Catalog Client Script for this purpose but it is not working:

 

SC Client Script.JPG

 

 

 

 

function onChange(control, oldValue, newValue, isLoading)

{

               if (isLoading)

               {

                              return;

               }             

               var oldName = g_form.getDisplayBox('old_name').value;

               g_form.setValue('old_name_hist', oldName);

}

 

Help would be greatly appreciated!

2 ACCEPTED SOLUTIONS

Kristen Ankeny
Kilo Sage

Try getDisplayValue instead to getDisplayBox

View solution in original post

Shakeel Shaik
Giga Sage
Giga Sage

Hi @Su522 ,

Once try this.

var oldName = g_form.getDisplayValue('old_name');
g_form.setValue('old_name_hist', oldName);
Thanks,
Shakeel Shaik 🙂

View solution in original post

2 REPLIES 2

Kristen Ankeny
Kilo Sage

Try getDisplayValue instead to getDisplayBox

Shakeel Shaik
Giga Sage
Giga Sage

Hi @Su522 ,

Once try this.

var oldName = g_form.getDisplayValue('old_name');
g_form.setValue('old_name_hist', oldName);
Thanks,
Shakeel Shaik 🙂