Direct and Indirect reportees of a given user

At times there are use cases or for reporting purpose where we need all the direct and indirect reportees of a manager i.e. complete list of users who are reporting the user in who is in the hierarchical reporting structure of given user, below code will help you to find all such direct and indirect reportees of a given user.

   import java.util.ArrayList;
   import java.util.List;
 
   import sailpoint.object.Identity;
   import sailpoint.object.QueryOptions;
   import sailpoint.object.Filter;
 
   import sailpoint.api.IncrementalObjectIterator;
 
   import sailpoint.tools.Util;
 
 
   public List getAllReportees(String identityName){
 
     List allreportees=new ArrayList();
 
     QueryOptions managerQO=new QueryOptions();
 
     managerQO.addFilter(Filter.eq("manager.name", identityName));
 
 // Below conditions can be modified based on your Projects conditions to identify a valid regular user account
 
     managerQO.addFilter(Filter.eq("correlated", true));
 
     managerQO.addFilter(Filter.ne("type", "Service"));
 
     managerQO.addFilter(Filter.ne("inactive", true));
 
 
 
     IncrementalObjectIterator<Identity identityIterator=new IncrementalObjectIterator<Identity(context, Identity.class, managerQO);
 
     while(identityIterator.hasNext())
 
     {
 
       Identity ident=(Identity)identityIterator.next();
       String userName=ident.getName();
 
       allreportees.add(userName);
 
       if(isManager(userName)){
 
         allreportees.addAll(getAllReportees(userName));
 
       }
 
 
     }
 
     Util.flushIterator(identityIterator);
     return  allreportees;
   }
 
 
   public boolean isManager(String identityName){
 
     boolean isManager=false;
 
     QueryOptions managerQO=new QueryOptions();
 
     managerQO.addFilter(Filter.eq("manager.name", identityName));
 
     managerQO.addFilter(Filter.ne("name", identityName));
 
 // Below conditions can be modified based on your Projects conditions to identify a valid regular user account
 
     managerQO.addFilter(Filter.eq("correlated", true));
 
     managerQO.addFilter(Filter.ne("type", "Service"));
 
     managerQO.addFilter(Filter.ne("inactive", true));
 
 
 
     IncrementalObjectIterator<Identity identityIterator=new IncrementalObjectIterator<Identity(context, Identity.class, managerQO);
 
     if(identityIterator.hasNext())
 
     {
 
       isManager=true;
 
     }
 
     return isManager;
 
   }
 
   List allReports=new ArrayList();
 
   return getAllReportees("USER_NAME");

Note - This can be used in use cases like where you want to validate the manager cyclic conditions etc.

3 Likes

Thanks @iamksatish for sharing this.
I guess we can add these methods in the rule library and reference this rule library in the custom rules ?

@vinnysail
Yes, absolutely correct, you can place this in a rule and reference in other rules or workflows directly based on your use case.

1 Like

@iamksatish : I dont get what do you mean by Indirect reportees , Direct reportees list we can easily fetch from analytics page :slight_smile:

@Saket95606
Indirect reportees refer to the employees or team members who do not directly report to a specific manager or leader but are one or more levels down in the organizational hierarchy. They report to someone who directly reports to the manager or leader. For instance, if you’re a department head, your direct reportees would be the team leaders under you, while the team members under those team leaders would be your indirect reportees, this can go under n number of levels until users doesn’t have reportees.

1 Like

Thanks for the clarification mate :slight_smile: