- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 01:11 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 03:45 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 02:49 AM
Hello @Brad Campbell
you can try the following script to check if the user is manager for anyone.
var user_id = gs.getUserID();
var usgr = new GlideRecord('sys_user');
usgr.addActiveQuery();
usgr.addQuery('manager', user_id); //checking if the given user (user_id) is manager for anyone.
usgr.setLimit(1);
usgr.query();
return usgr.hasNext(); //returns true if user is manager
Help others to find a correct solution by marking the appropriate response as correct answer and helpful!!
Regards,
Ravi Chandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 03:16 AM
Hi Ravi
I get an error when trying to save your code in the user criteria script field...
Could not save record because of a compile error: JavaScript parse error at line (7) column (7) problem = invalid return (<refname>; line 7)
Thanks
Brad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 03:44 AM
Hello @Brad Campbell
can you replace 7th line with
if(usgr.hasNext())
return true;
Regards,
Ravi Chandra.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 03:45 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 03:53 AM
Thank you Ankur. This works perfectly!