- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2025 08:04 PM
When a specific Catalog Item is selected, I want to automatically populate the review_manager variable (reference to sys_user), which is inside a Variable Set for reusability.
If the Catalog Item is:
sys_id: CATALOG_ITEM_SYS_IDThen the approver (review_manager) should be the Manager of the group:
sys_id: GROUP_SYS_ID
------
What I’ve done so far
Script Include
var GetCatalogItemApprover = Class.create();
GetCatalogItemApprover.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApprover: function() {
var catalogItemId = this.getParameter('sysparm_catalog_item');
if (catalogItemId == '8680af5133b26a10219be1f13d5c7bce') {
var group = new GlideRecord('sys_user_group');
if (group.get('9016d41b83ea1250145417447daad3f2')) {
return group.getValue('manager') || '';
}
}
return '';
}
});
- Catalog Client Script (Applies to: variable Set)
function onLoad() {
var catalogItemId = g_form.getValue('sysparm_item_guid');
var ga = new GlideAjax('GetCatalogItemApprover');
ga.addParam('sysparm_name', 'getApprover');
ga.addParam('sysparm_catalog_item', catalogItemId);
ga.getXMLAnswer(function(answer) {
if (answer) {
g_form.setValue('review_manager', answer);
}
});
}
- Ref qualifier review_manager
The Issue:
My variable displays all user not just the manager for the group.Any insights on why the review_manager is not displaying the user even though a sys_id is being set?
Is there a better approach to dynamically populate a reference field in a Variable Set on Catalog Item load?
Any guidance or examples would be greatly appreciated!
Thanks in advance,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2025 09:33 PM - edited 07-20-2025 10:37 PM
okay then do this in onLoad catalog client script Applies to Catalog Item
function onLoad() {
var url = top.location.href;
var ga = new GlideAjax('GetCatalogItemApprover');
ga.addParam('sysparm_name', 'getApprover');
ga.addParam('sysparm_catalog_item', url);
ga.getXMLAnswer(function(answer) {
if (answer) {
g_form.setValue('review_manager', answer);
}
});
}
Script Include:
var GetCatalogItemApprover = Class.create();
GetCatalogItemApprover.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApprover: function() {
var url = this.getParameter('sysparm_catalog_item');
if (url.indexOf('8680af5133b26a10219be1f13d5c7bce') > -1) {
var group = new GlideRecord('sys_user_group');
if (group.get('9016d41b83ea1250145417447daad3f2')) {
return group.getValue('manager') || '';
}
}
return '';
}
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2025 08:20 PM
I suggest add your code to reference Reference qualifier instead of using client script or change the field type to look up field and using client script to clear the options and add the correct option to field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2025 09:00 PM
is that variable set used across multiple catalog items and hence you want to check the catalog item sysId?
you want to populate that user variable with which group manager?
You told Manager of group -> which one? is that a variable on catalog form?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2025 09:22 PM
Hi @Ankur Bawiskar,
Thanks for the reply!
Yes — the Variable Set is designed to be reusable across multiple Catalog Items, which is why I’m checking the Catalog Item sys_id.
To clarify:
For the Catalog Item with sys_id: 8680af5133b26a10219be1f13d5c7bce.
I want the review_manager variable (reference to sys_user) to be automatically populated with the Manager of the group with sys_id: 9016d41b83ea1250145417447daad3f2.
-----
When I say “Manager of the group”, I’m referring to the manager field on the Group record in sys_user_group — not a variable on the form.
Thanks again for your help!
Regards,
Juan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2025 09:33 PM - edited 07-20-2025 10:37 PM
okay then do this in onLoad catalog client script Applies to Catalog Item
function onLoad() {
var url = top.location.href;
var ga = new GlideAjax('GetCatalogItemApprover');
ga.addParam('sysparm_name', 'getApprover');
ga.addParam('sysparm_catalog_item', url);
ga.getXMLAnswer(function(answer) {
if (answer) {
g_form.setValue('review_manager', answer);
}
});
}
Script Include:
var GetCatalogItemApprover = Class.create();
GetCatalogItemApprover.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApprover: function() {
var url = this.getParameter('sysparm_catalog_item');
if (url.indexOf('8680af5133b26a10219be1f13d5c7bce') > -1) {
var group = new GlideRecord('sys_user_group');
if (group.get('9016d41b83ea1250145417447daad3f2')) {
return group.getValue('manager') || '';
}
}
return '';
}
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader