- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 03:09 PM
Hi Guys,
I'm trying to populate manager name of an employee in a catalog item. This form once loaded will contain logged in user's name and the manager name should display in the "hiring_manager" field. If it's changed at any point then the field should clear and bring the new user's manager name.
I have got this right with the client script below but only if I change the "hiring_manager" field to a simple text field. It is originally a reference field and I can't change it as it impacts to the workflow of the catalog item. Once I change the hiring manager field back to "reference", script stops working.
Please advise. I'm not from a dev background so any help is appreciated.
-------------------------------------------------------------------------------------------------------
function onChange(control, oldValue, newValue, isLoading) {
if (/*isLoading ||*/ newValue == '') {
return;
}
//Populate Manager Name
var userMobilega = new GlideAjax('XXUserDetailsAjax');
userMobilega.addParam('sysparm_name', "getManager");
userMobilega.addParam('sysparm_requestor', g_form.getValue("requested_for_set"));
userMobilega.getXMLAnswer(handleResponseManager);
function handleResponseManager(response) {
// alert(response);
if (response) {
g_form.setValue("hiring_manager", response);
}
}
}
**XXUserDetailsAjax - this is a function written by our vendor with nested functions to bring various different fields from sys_user record.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 04:40 PM - edited 12-22-2022 04:40 PM
Add this new function to the script include
//Get User's Manager sysid
getManagerSysId: function() {
var user = this.getParameter('sysparm_requestor');
var userGR = new GlideRecord("sys_user");
userGR.addQuery("sys_id", user);
userGR.query();
if (userGR.next()) {
return userGR.getValue('manager');
}
},
And your client script updated to
function onChange(control, oldValue, newValue, isLoading) {
if (/*isLoading ||*/ newValue == '') {
return;
}
//Populate Manager Name
var userMobilega = new GlideAjax('XXUserDetailsAjax');
userMobilega.addParam('sysparm_name', "getManagerSysId");
userMobilega.addParam('sysparm_requestor', g_form.getValue("requested_for_set"));
userMobilega.getXMLAnswer(handleResponseManager);
function handleResponseManager(response) {
// alert(response);
if (response) {
g_form.setValue("hiring_manager", response);
}
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 04:37 PM
Thank you so much, Sanjiv.
Here's the getmanager function that is sitting inside 'XXUserDetailsAjax'
-----------------------------
//Get User's Manager
getManager: function() {
var user = this.getParameter('sysparm_requestor');
var userGR = new GlideRecord("sys_user");
userGR.addQuery("sys_id", user);
userGR.query();
if (userGR.next()) {
return userGR.manager.getDisplayValue();
}
},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 04:40 PM - edited 12-22-2022 04:40 PM
Add this new function to the script include
//Get User's Manager sysid
getManagerSysId: function() {
var user = this.getParameter('sysparm_requestor');
var userGR = new GlideRecord("sys_user");
userGR.addQuery("sys_id", user);
userGR.query();
if (userGR.next()) {
return userGR.getValue('manager');
}
},
And your client script updated to
function onChange(control, oldValue, newValue, isLoading) {
if (/*isLoading ||*/ newValue == '') {
return;
}
//Populate Manager Name
var userMobilega = new GlideAjax('XXUserDetailsAjax');
userMobilega.addParam('sysparm_name', "getManagerSysId");
userMobilega.addParam('sysparm_requestor', g_form.getValue("requested_for_set"));
userMobilega.getXMLAnswer(handleResponseManager);
function handleResponseManager(response) {
// alert(response);
if (response) {
g_form.setValue("hiring_manager", response);
}
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 04:49 PM
This worked perfectly!! thank you so much Sanjiv and Kartik for the answer earlier.
Do you guys have any suggestion for a script training course for a newbee like myself (nowlearning or youtube?)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 04:55 PM
There are lot of videos on youtube which you can watch
https://www.youtube.com/watch?v=62Nabpb94Jw&list=PL3rNcyAiDYK2_87aRvXEmAyD8M9DARVGK
https://www.youtube.com/watch?v=P7yLpHCbnfo&list=PLzTvAeLiW8AfXEIFrUp-22z512aXxr2Ss
Please mark this response as correct or helpful if it assisted you with your question.