How to check if a user is a manager
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2016 08:34 PM
How to check if a user is a manager considering user table has large number of records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 08:45 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 09:47 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 08:49 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2020 05:24 PM