- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
Upon clicking the button , need to et the current logged in user Manager Name and Manager's manger name , ned entire hierachy.
I have wrote this script and will use it in UI Actions , and show it in Incident feild .
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Saturday
@naveenvenka I have created this recursive function for you. You can test this function via a background script and it will give the the entire manager hierarchy without causing any performance issues.
function getManagerHierarchy(managerArray, next) {
var glideRecord = new GlideRecord('sys_user');
if (glideRecord.get(next)) {
managerArray.push(glideRecord.manager.name + '');
return getManagerHierarchy(managerArray, glideRecord.getValue('manager'));
} else {
return managerArray.toString();
}
}
var managerArray = [];
gs.info(getManagerHierarchy(managerArray, 'b13cb325931721100143ad44246a4db0')); //Pass the sys_id of person here
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Saturday
@naveenvenka I have created this recursive function for you. You can test this function via a background script and it will give the the entire manager hierarchy without causing any performance issues.
function getManagerHierarchy(managerArray, next) {
var glideRecord = new GlideRecord('sys_user');
if (glideRecord.get(next)) {
managerArray.push(glideRecord.manager.name + '');
return getManagerHierarchy(managerArray, glideRecord.getValue('manager'));
} else {
return managerArray.toString();
}
}
var managerArray = [];
gs.info(getManagerHierarchy(managerArray, 'b13cb325931721100143ad44246a4db0')); //Pass the sys_id of person here
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Saturday
Try this!
// Get the logged-in user
var userGR = new GlideRecord('sys_user');
if (userGR.get(gs.getUserID())) {
var managersChain = [];
var managerID = userGR.getValue('manager');
while (managerID) {
var mgr = new GlideRecord('sys_user');
if (mgr.get(managerID)) {
managersChain.push(mgr.getDisplayValue('name')); // manager's name
managerID = mgr.getValue('manager'); // move to next manager
} else {
break;
}
}
var hierarchy = managersChain.join(" > ");
gs.info("Manager Hierarchy: " + hierarchy);
} else {
gs.info("No user record found for current session.");
}
I have tried it on PDI (Background script) and its working!
Hope it helps!
Shashank Jain – Software Engineer | Turning issues into insights