List of users based on department head

Amit Patwal1
Tera Contributor

Hi Experts,

 

I have a requirement where I want to build a dynamic filter, where I can pull list of user based on department head.

 

User list should also contain all the child departments hierarchy. How can I achieve that?

 

Regards,

Amit Patwal

3 REPLIES 3

Slava Savitsky
Giga Sage

There are different ways to do that. How deep is your departments hierarchy? And what is the exact use case? Do you want just your department heads to have a filter like getAllPeopleFromMyDepartments? Or do you want any user to be able to select a department head and see who belongs to that person's departments? And where do you want to use that filter? In a normal list in Core UI or elsewhere?

I want to get list of users which I am using in my flow to be sent to third party system for some actions.

 

Departments hierarchy can change so level can be added or removed in future.

 

Regards,

AP

Then this is the approach you could take:

 

1. Write a function that retrieves the child departments of a given department and pushes their IDs into an array.

 

2. Given the name of a department head, use a GlideRecord query to find all departments that person is heading.

 

3. Use your function from step 1 above to recursively retrieve child departments of those departments as well as their children and the children of their children, etc. Push the IDs of all found departments into an array. As a precaution against an infinite loop, make sure to add a control to stop the recursion after a predefined number of nesting levels.

 

4. Finally, use GlideRecord to retrieve the list of the users. Use 'IN' operator to query for multiple departments at once.