Need to give role conditions in user criteria for record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 02:23 AM
Add a user criteria for user has role 'SM' && 'sn_customerservice_agent', set as the 'Can View' for this record producer.
The above statement is requirement, Should I write script in user criteria? like below;
allow();
function allow() {
if (gs.getUser().hasRole('SM') && gs.getUser().hasRole('sn_customerservice_agent')) {
return true;
}
}
or any other way?
I gave two roles in roles of user criteria, but if user has any one role, he is getting access...here requirement is to check if user has both the roles.
- Labels:
-
Cost Management (ITSM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 02:31 AM
Hi,
if you give those 2 roles in roles field on user criteria then when either role is present it would allow since you want both roles to be present use script
yes write in user criteria script
allow();
function allow() {
if (gs.getUser().hasRole('SM') && gs.getUser().hasRole('sn_customerservice_agent')) {
return true;
}
else
return false;
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
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-29-2020 04:15 AM
For some reason this is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 04:22 AM
Hi,
Did you check the role name is correct?
try adding debug to check where it is failing?
allow();
function allow() {
if(gs.getUser().hasRole('SM') && gs.getUser().hasRole('sn_customerservice_agent')) {
gs.info('User has both the roles');
return true;
}
else
return false;
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
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-29-2020 04:18 AM
Hi there,
Try to add some debugging to see if the hasRole actually returns true or false? Also is the role SM with uppercase?
Example debugging:
gs.info('>>> DEBUG: ' + gs.getUser().hasRole('SM'));
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field