Autopopulate the Manager field in the catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hello,
I need to automatically populate the Approving Manager variable in a ServiceNow catalog item based on the following logic:
- If the Is this request for you? variable is Yes, then the manager of the Requested by user should be auto-populated in the Approving Manager field.
- If the Is this request for you? variable is No, then the manager of the user specified in the On Behalf of variable should be auto-populated in the Approving Manager field.
Could someone guide me on how to implement this?
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
something like this in onchange catalog client script
Ensure you give correct variable names
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.clearValue('approving_manager'); // approving manager variable name here
}
var variableToPick = '';
if (newValue == 'yes')
variableToPick = 'requested_by'; // requested by variable name
else if (newValue == 'no')
variableToPick = 'on_behalf_of'; // on behalf of variable name
var ref = g_form.getReference(variableToPick, callBackMethod);
}
function callBackMethod(ref) {
if (ref.manager)
g_form.setValue('approving_manager', ref.manager); // approving manager variable name here
}
💡 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
Hello Ankur,
I have tried with the above script but it is not auto populating.
All those variable are existing in the variable set. I wrote the above client script in the variable set itself
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
it should work fine provided you are comparing correct values and correct variable names
share your client script screenshot along with variable backend name etc
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
