- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2018 02:28 PM
How to get current loggedin user's manager name and email id?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2022 03:54 AM
Hi,
If it's absolutely necessary to create a client script, following will get current user's manager's info.
Client script
function onLoad() {
var ajax = new GlideAjax('UserUtilClient');
ajax.addParam('sysparm_name', 'getManagerInfo');
ajax.getXMLAnswer(function(answer) {
if (answer.length > 0) {
var json = JSON.parse(answer);
g_form.setValue('manager_name', json.name);
g_form.setValue('manager_email', json.email);
}
});
}
Script include
var UserUtilClient = Class.create();
UserUtilClient.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManagerInfo: function() {
var grUser = new GlideRecord('sys_user');
if (grUser.get(gs.getUserID())) {
var manager = grUser.manager;
if (manager) {
return JSON.stringify({
"name": manager.name.toString(),
"email": manager.email.toString()
});
}
}
},
type: 'UserUtilClient'
});
The result is a same as when using default value. This is a little bit slower because the form is loaded and then the form makes an ajax request to the server to get manager's information. When setting the default value, manager's name and email is filled when before the form is loaded so there's no ajax call after the form is loaded.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2018 03:03 PM
Hi,
Use
var currentUser = gs.getUserID();
var gr=new GlideRecord('sys_user');
gr.get(currentUser);
gs.log(gr.email);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2018 05:38 PM
Please use below in your script to get current user's manager and email
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
gs.print(user.manager.name);
gs.print(user.manager.email);
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2018 06:43 PM
Here goes a simple way to do it 🙂
var email = gs.getUser().getEmail(); //This will retrieve the email
var managerID = gs.getUser().getRecord.getValue('manager'); //This will retrieve the Manager ID (sys_id).
If you're recording for logging/audit purposes the manager or if you want to use it for other operations, using the sys_id might be a more robust way to approach it than using the name. If you still want the name of the manager... you can do something like...
var userGR = new GlideRecord('sys_user');
userGR.get (gs.getUser().getRecord.getValue('manager'));
var managerName = userGR.name;
I hope it helps! 🙂
Thanks,
Berny

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2018 06:46 PM
Hi,
The real question is, how are you planning to do this? BR? Client Script, etc?
Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!