Auto-Populate Variable in One Variable Set from Another Variable Set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Yes, Working perfectly!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I hope you tried using a single-row variable set for both cases, correct? In my scenario, the global_variable_set is of type Single Row, while the business_app_update variable set is of type Multi Row.
It’s not working for me in this setup. Could you please share a solution or script that works for this specific scenario?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Sirri , then you need to write a onload client script on MRVS and then you need to read the value of global variable in your script.
Checkout this recent Article posted:
Auto-Populate Variable in One Variable Set from Another Variable Set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you can create onChange catalog client script which Applies to Catalog Item
Then select your requested_for variable
Then copy the value to your other variable
This ensures the onChange runs only on your catalog item and not on other catalog items which uses that Global Variable Set
Also don't make that variable read-only via variable config, as soon as you populate make it readonly
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '')
g_form.clearValue('is_key_person_risk_attested_by1');
if (oldValue != newValue) {
g_form.setValue('is_key_person_risk_attested_by1', newValue); // 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! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I hope this works in case of both variable set of type is single.
I hope you tried using a single-row variable set for both cases, correct? In my scenario, the global_variable_set is of type Single Row, while the business_app_update variable set is of type Multi Row.
It’s not working for me in this setup. Could you please share a solution or script that works for this specific scenario?
Thank you!
