User criteria to check if user is Manager AND he belongs to specific Location
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 03:47 AM
Hi all, I have a condition where if a user belongs to Location: Wroclaw and if he "Is Manager", then only the record producer is visible, I tried writing the script and added Wroclaw iin locations and checked "Match all". But it is not working. Any idea on how to do this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 04:04 AM
Always remember to paste what you have written ? Anyways please add below code to advance section and also check 'Match all' check to true
Code:
answer = checkIfManager();
function checkIfManager(){
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', gs.getUserID());
gr.query();
return gr.hasNext();
}
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 04:33 AM
I have written the same code. It is not working if location is also selected

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 05:36 AM
Screenshot ?
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 04:16 AM
Hi,
use script to cover all cases
answer = checkCondition();
function checkCondition(){
var gr = new GlideRecord("sys_user");
gr.addQuery("manager", user_id);
gr.setLimit(1);
gr.query();
var rec = new GlideRecord('sys_user');
rec.get(user_id);
var locationName = rec.location.name;
if(gr.hasNext() && locationName.indexOf('Wroclaw') > -1)
return true;
else
return false;
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader