- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2020 11:33 PM
Hi All,
I have a User criteria with following conditions in the Available for related list:
if(gs.hasRole('rolename')){
return true;
}
else if(gs.isMemberOf('grp_name')){
return false;
}
else {
return false;
}
When testing its not working properly, first I added the role used in condition to the user then that particular category was visible - correct working. Then removed the role and added user to the group, the category is still visible.It should not be visible- not working.
I have tried clearing cache, and when logs were added to the user criteria noticed that it only works first time when impersonated by the user.
How to fix this?
Regards,
Snehal K
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 04:50 AM
Hi All,
Thanks for the advice. After further testing found that it was a cache issue. The script worked properly,checked by logs.
After clearing the cache it worked properly
Thanks,
Snehal Khare

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 04:59 AM
Confirming that you checking for hasRole() part users as anyways for other's its false & should not appear.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 01:09 AM
Hi Snehal,
So are you saying catalog item should be visible if
1) user is either having that role or member of that group
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
04-28-2020 11:55 PM
Hi
You need to impersonate or log off/on after every change of Roles or Groups of that given user.
The roles and groups are pulled at log in.
So, please retry your scenario with fresh login at each test.
Let me know if that answers your question and mark my answer as correct/helpful, please.
BR
Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 03:49 AM
It doesn't work either. Tried it already.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 04:55 AM
Hi
Make sure, that there are no other conflicting User Criteria attached, which may interfere with the one you are testing. Make sure for testing, that ONLY the desired User Criteria is in place.
Otherwise, testing may become cumbersome..
Let me know, if that works out.
BR
Dirk