The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to check if a user is a manager

karthiknagaramu
Kilo Sage

How to check if a user is a manager considering user table has large number of records.

8 REPLIES 8

Hi Shawn,



Thanks for the suggestion. I am little worried about the performance here in case if we have large number of records in user table. Do you think creating a new field in user to mark the user as manager would be a good idea.



Regards,


KN


Hi Karthik,



It is better u can create a new field "is manager" and run the below script in "Scripts - Background". This is a one time activity.



Similarly write a script in business rule, because if any record updated or created then "is Manager" field will get updated.



var usr=new GlideRecord('sys_user');          


usr.query();


while(usr.next()){


              var user=new GlideRecord("sys_user");


              user.addQuery('manager',usr.sys_id);


              user.query();


              if(user.next()){


                                              user.u_is_manager=true;


                                              user.update();


                              }


}



-Giri


True, it would have to hit the database each time this is run, but using setLimit(1) will only return a single record if one exists and then stop. The impact should be minimal unless you are doing this in a client script that runs very frequently. If it's in a business rule or script include, it shouldn't have any negative effect.


kklosterman
Giga Guru
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', gs.getUserID());
gr.query();
gr.getRowCount() > 0;

 

find_real_file.png