User Criteria: Identify line managers

Brad Campbell
Tera Contributor

Morning community,

 

Probably a common ask but I can't find a previous post that fits the bill. We have a catalogue item that we want to restrict to just managers i.e. those who appear in the manager field of any user in the sys_user table.

 

Any help appreciated as always.

 

Thanks, Brad

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Brad Campbell 

use script inside user criteria

this will work fine

var userRec = new GlideRecord('sys_user');
userRec.addQuery('manager', user_id);
userRec.setLimit(1);
userRec.query();
answer = userRec.hasNext(); 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Alp Utku
Mega Sage

I would suggest you to create a group containing managers in your company. Then you can restrict the catalog Item visible for this group only.

Hi Alp,

 

Thanks for your response. This is obviously a solution but would would be an admin overhead for the platform team, the idea would be to use a script and leverage the information we already have in the sys_user table rather than running a report and manually adding them every week.

You can use the below script on user criteria

 

checkCondition();

function checkCondition(){

var user = new GlideRecord('sys_user');

user.get(gs.getUserID());

if (user.manager !="")
{
     return true;
}
return false;
}

Thanks Alp,

 

When testing this script the behaviour is only restricting access to the catalogue item for a logged in user where their manager field is empty rather than the logged in user not appearing in the manager field of another sys_user.

 

Thanks

 

Brad