- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2024 09:53 PM
How can I create a custom script include to retrieve the name of the current user's manager in ServiceNow?
Solved! Go to Solution.
- 650 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2024 11:18 PM - edited ‎10-14-2024 11:19 PM
Hi @mahesh009
Try this custom script include (To create in ServiceNow to retrieve the name of the current user's manager).
var MyManager = Class.create();
MyManager.prototype = {
initialize: function() {
},
getManagerName: function() {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
if (gr.next()) {
var managerID = gr.manager.sys_id;
if (managerID) {
var managerGr = new GlideRecord('sys_user');
managerGr.addQuery('sys_id', managerID);
managerGr.query();
if (managerGr.next()) {
return managerGr.first_name + ' ' + managerGr.last_name;
}
}
}
return 'No manager found';
}
};
To use this script include, you can call the getManagerName() method from your business rules, client scripts, or other ServiceNow components. For example, in a business rule:
var managerName = new MyManager().getManagerName();
gr.setValue('manager_name', managerName);
This script include first retrieves the current user's sys_id. Then, it queries the sys_user table to find the manager's sys_id. Finally, it queries the sys_user table again to retrieve the manager's name. If no manager is found, the script returns "No manager found."
Thanks, and Regards
Vishaal
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
‎10-14-2024 10:06 PM
Hello @mahesh009
Refer the below thread:
Please mark this answer as helpful and correct if helped
Kind Regards,
Ravi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2024 10:28 PM
You can do it with this
var managerID = gs.getUser().getManagerID();
also refer to https://servicenowguru.com/scripting/user-object-cheat-sheet/ in case you need another method to retrieve user related data without much scripting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2024 11:18 PM - edited ‎10-14-2024 11:19 PM
Hi @mahesh009
Try this custom script include (To create in ServiceNow to retrieve the name of the current user's manager).
var MyManager = Class.create();
MyManager.prototype = {
initialize: function() {
},
getManagerName: function() {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
if (gr.next()) {
var managerID = gr.manager.sys_id;
if (managerID) {
var managerGr = new GlideRecord('sys_user');
managerGr.addQuery('sys_id', managerID);
managerGr.query();
if (managerGr.next()) {
return managerGr.first_name + ' ' + managerGr.last_name;
}
}
}
return 'No manager found';
}
};
To use this script include, you can call the getManagerName() method from your business rules, client scripts, or other ServiceNow components. For example, in a business rule:
var managerName = new MyManager().getManagerName();
gr.setValue('manager_name', managerName);
This script include first retrieves the current user's sys_id. Then, it queries the sys_user table to find the manager's sys_id. Finally, it queries the sys_user table again to retrieve the manager's name. If no manager is found, the script returns "No manager found."
Thanks, and Regards
Vishaal
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
‎10-16-2024 12:44 AM
Hi @mahesh009
Refer the below link
use GlideRecord API and query the logged in user and retrieve the manage name.
Thank you.