Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**Get the complete hierarchy of the managers for a given user.**
This script uses a recursive function to fetch the complete list of managers for any given user. Consider the following example.
<img width="929" height="298" alt="Screenshot 2025-10-20 at 1 29 11 AM" src="https://github.com/user-attachments/assets/aeeb718c-e528-4ff7-b4e1-f3d5d9772791" />

In this example user Abel Tutor reports to Abraham Lincoln, Abrham reports to Adela Cervantsz, Adela reports to Aileen Mottern and so on.

In order to fetch this complete hierachy the getManagerHierachy script can be used. Here is the example of this script with output.
<img width="1394" height="635" alt="Screenshot 2025-10-20 at 1 34 36 AM" src="https://github.com/user-attachments/assets/32fa4369-9743-4335-854f-63bdaf20f6e4" />


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//Recursive function to get the complete manager hierarchy
//Param 1: managerArray an Array to hold manager hierarchy
//Param 2: next is representing next person in the manager hierarchy
function getManagerHierarchy(managerArray, next) {
var glideRecord = new GlideRecord('sys_user');
if (glideRecord.get(next)) {//Check if there is a user record
managerArray.push(glideRecord.manager.name + '');//Add the user detail to the manager array
return getManagerHierarchy(managerArray, glideRecord.getValue('manager')); //Recursively call the same method to get the details of manager

} else {//No more manager found return the array to callling function
return managerArray.toString().split(',').join(" >> ").substring(0, managerArray.toString().split(',').join(" >> ").length-4);
}
}

var managerArray = [];
gs.info(getManagerHierarchy(managerArray, '22826bf03710200044e0bfc8bcbe5dec')); //Pass the sys_id of person here
Loading