Auto-Populate Variable in One Variable Set from Another Variable Set

Sirri
Tera Guru

Hi All,

I have a requirement in the Service Catalog:

  • There is a global variable set named global_variable_set which contains a field requested_for (type: Reference to User). This field is editable, and the user can change it multiple times.
  • There is another variable set named business_app_update which is specific to one catalog item. In this set, there is a field is_key_person_risk_attested_by1 (type: Reference to User) that is read-only.

I need to auto-populate the read-only field (is_key_person_risk_attested_by1) with the value from requested_for whenever it changes.

Please note:

  • The global variable set is used in multiple catalog items.
  • The business_app_update variable set is specific to one catalog item.

Could you please guide me on how to achieve this? If you can share a sample script, that would be great.

Thank you in advance for your support!

11 REPLIES 11

kaushal_snow
Giga Sage

@Sirri ,

 

Use a catalog client script that watches for changes to the requested_for field and then sets the value of your target variable (is_key_person_risk_attested_by1) accordingly on the form (for example using g_form.setValue('is_key_person_risk_attested_by1', g_form.getValue('requested_for')); in an onChange script........so whenever the user changes the requested_for field the risk attested field is updated to match or you can also initialize it on form load with an onLoad script as long as both variables are present on the catalog item form and have variable names, which is the typical way to copy one catalog variable value to another..............

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Technical Consultant - ServiceNow Class of Legends 2025

@kaushal_snow ,

 

Thank you for your response. I have tried this it will not work. Please try and share the result if it works for you.

 

Thank you

Siddhesh Gawade
Mega Sage

Hello @Sirri ,

 

You can write a simple onChange Client script directly on catalog item level (not on variable set). See my below example.
1. "requested_for" is global variable, part of variable set 1.

2. "name" is another variable in another variable set 2. 
3.  See how I able to select global variable in attached screenshot. you can do the same and set the value of dependent variable (in my case it is name) using getReference or GlideAjax.

 

SiddheshGawade_0-1766044397260.png

Example:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

var userID = g_form.getValue('requested_for');
g_form.getReference('requested_for' , getuserDetails);  // Access global variable 

function getuserDetails(userRecord){
      g_form.setValue('name', userRecord.name.toString());  // Set the dependent variable
   }


}

 

Regards,
Siddhesh Gawade

 

@Siddhesh Gawade ,

 

Thank you for your response. Have you tested this is it worked for you.

 

Thank you