- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 12:46 AM
Hi
I want a user criteria to both match user group and a location that is on the user.
But this doesn't work. Do I have to script? I am novice at scripting, How would such a script look?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 07:48 AM
Hi,
I would encourage to have step by step debug
1) check if member of Hardware is able to access the catalog
Keep Script as: Test with user
answer = gs.getUser().isMemberOf('Hardware');
Next
2) check if user's location condition is satisfied
Keep Script as: Test with user having that location
answer = ifScript();
function ifScript(){
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', gs.getUserID());
user.addQuery('location', '25ab9d720a0a0bb300793d3a6b891f82');
user.query();
var locationValid = user.hasNext();
return locationValid;
}
3) Now combine both the codes and check by adding logs
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 12:57 AM
Match All should work, if you want to script this follow:
you can use( as per your current condition):
checkcondition();
function checkcondition()
{
if((gs.getUser().getRecord().getValue('location')=='location1 sys_id' || gs.getUser().getRecord().getValue('location')=='location2 sys_id')&& gs.getUser().isMemberOf('assignment_group_sys_id'))
{
return true;
}
else{
return false;
}
}
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 01:04 AM
MAtch all does not work. If I Impersonate a user in Hardware I can access this even if I belong to another location in my user account
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 01:29 AM
I tried:
checkCondition();
function checkCondition(){
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
if (user.location=="25ab9d720a0a0bb300793d3a6b891f82")
{
return true;
}
return false;
}
It still doesn't not work.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 12:57 AM
Hi Daniela
yes for that you have to write script.
refer the following link it might help you.
https://community.servicenow.com/community?id=community_blog&sys_id=925219751b358850d01143f6fe4bcb7b
If it help mark helpful or correct
Thanks and regards
Anil