Blog

Manager Employee List

This is a method to pull a manager's employee list (hierarchy).  A list of all the employee's a manager has, and who they manage, down to a specified number of levels.

Script Include: getManagerEmployees

Client Callable: true
Script:

function getManagerEmployees () {

var userList = [];
var maxLevel = 5; //Adjust for levels you want to recurse
var level = 1;
var grUser1 = new GlideRecord('sys_user');
if (grUser1.get(gs.getUserID())) {
recurseUsers(grUser1.sys_id.toString(),level,maxLevel,userList);
}

function recurseUsers (manager, level,maxLevel,userList) {
var grUser2 = new GlideRecord('sys_user');
grUser2.addQuery('manager',manager);
grUser2.addActiveQuery();
grUser2.query();
while(grUser2.next()) {
userList.push(grUser2.sys_id.toString());
if (level+1 <= maxLevel ) {
recurseUsers(grUser2.sys_id.toString(),level + 1,maxLevel,userList);
}
}

} 

return userList; 
}

Scripted filter

With that script include above, you can use it in a filter.

1. In the Left Navigator, click User Administration > Users
2. Add a filter: Sys ID is one of javascript:getManagerEmployees();

Module

You can also add a module that shows managed employees

1. Add Module

My Managed Employees
Table: User [sys_user]
Filter: Sys ID is one of javascript:getManagerEmployees();