- 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
‎03-19-2023 07:20 AM
Hi @Hitoshi Ozawa Hitoshi, Thanks for your answer, can you tell me how to get the currently logged-in user's manager name and email id using the g_scratchpad display business rule