Skip to content

Commit 66a4d7b

Browse files
Create getManagerHierarchy.js
Function to get the complete manager hierarchy
1 parent 0a66b30 commit 66a4d7b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//Recursive function to get the complete manager hierarchy
2+
//Param 1: managerArray an Array to hold manager hierarchy
3+
//Param 2: next is representing next person in the manager hierarchy
4+
function getManagerHierarchy(managerArray, next) {
5+
var glideRecord = new GlideRecord('sys_user');
6+
if (glideRecord.get(next)) {//Check if there is a user record
7+
managerArray.push(glideRecord.manager.name + '');//Add the user detail to the manager array
8+
return getManagerHierarchy(managerArray, glideRecord.getValue('manager')); //Recursively call the same method to get the details of manager
9+
10+
} else {//No more manager found return the array to callling function
11+
return managerArray.toString().split(',').join(" >> ").substring(0, managerArray.toString().split(',').join(" >> ").length-4);
12+
}
13+
}
14+
15+
var managerArray = [];
16+
gs.info(getManagerHierarchy(managerArray, '22826bf03710200044e0bfc8bcbe5dec')); //Pass the sys_id of person here

0 commit comments

Comments
 (0)