How to auto populate the value of manager first name in a user defined field on incident table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2025 10:39 AM
I write this line but it didn't fetch anything please suggest me correct way
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2025 09:24 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2025 09:49 PM
sorry your requirement is not clear.
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-28-2025 09:58 PM
HI @harshchaudh
Can you please try like this
If you want to auto-populate a custom field (e.g., u_mg) with the first name of the manager of a user (like caller_id), you must use the field name, not the label.
Here’s how to do it using a Client Script (onChange of caller_id):You can write for onload also same to use it for on open of exiting record.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('GetManagerFirstName');
ga.addParam('sysparm_name', 'getManagerFirstName');
ga.addParam('sysparm_user_id', newValue); // caller_id sys_id
ga.getXMLAnswer(function(response) {
g_form.setValue('u_mg', response); // u_mg is your custom field
});
}
And the Script Include (server-side): Script include need to be client callable.
var GetManagerFirstName = Class.create();
GetManagerFirstName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManagerFirstName: function() {
var userId = this.getParameter('sysparm_user_id');
var userGR = new GlideRecord('sys_user');
if (userGR.get(userId)) {
var managerGR = new GlideRecord('sys_user');
if (managerGR.get(userGR.getValue('manager'))) {
return managerGR.getValue('first_name');
}
}
return '';
}
});
Stay awesome,
Roshnee Dash