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

@Sirri 

In your original question you didn't tell the 2nd variable set is MRVS

Then the above script won't work

you will require this onLoad catalog client script which runs on your 2nd Variable Set i.e. MRVS

It will access outside variable and set the MRVS variable and make it readonly

function onLoad() {

    var reqFor = g_service_catalog.parent.getValue("requested_for");

    if (reqFor != '') {
        g_form.setValue('is_key_person_risk_attested_by1', reqFor); // Set the other variable
        g_form.setReadonly('is_key_person_risk_attested_by1', true);
    }
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Sirri 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader