- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 11:38 PM
Hi Community,
I need your help with debugging auto populating scripts.
I have create script include and client script to auto populate manager field when user is selected on the form.
When I select user while raising form, the manager name is populated successfully. But after submission of ritm, the manager name is disappeared.
Also, Client script is selected to Run on Catalog item, RITM, Catalog task. So, I'm confused what is causing this issue.
Please find below scripts i've used:
Script include:
// Script Include: ManagerLookup
var ManagerLookup = Class.create();
ManagerLookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManagerName: function () {
var userId = this.getParameter('sysparm_user_id');
var userGR = new GlideRecord('sys_user');
if (userGR.get(userId)) {
return userGR.manager.getDisplayValue();
}
return '';
},
type: 'ManagerLookup'
});
Client Script:
// Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || newValue === oldValue) {
return;
}
// Get the selected user's Sys ID
var userId = g_form.getValue('variables.employee_to_offboard');
// Call the Script Include using GlideAjax
var ga = new GlideAjax('ManagerLookup');
ga.addParam('sysparm_name', 'getManagerName');
ga.addParam('sysparm_user_id', userId);
ga.getXMLAnswer(function (answer) {
// Assuming your manager field is named 'manager' on the catalog item
g_form.setValue('variables.manager', answer);
});
}
Please suggest what I am missing here?
Thanks in Advance,
Hritik
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 11:43 PM - edited 02-01-2024 11:46 PM
Hi @Hritik
Is the manager field a reference field or String field, if its reference field, in Script Include just return user.manager . If this is not the case then if you have a variable within the variable set that has the same name as the internal name of the variable set, the value will not be saved in the RITM
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 11:38 PM
Hi Priyanka,
Thanks for the response. Noted.
But again there's twik in the requirement and now I need to auto populate user name based on Employee Number given that too via API call.
Please see below thread:
Please let me know if you can help.