Need to give role conditions in user criteria for record producer

rambo1
Tera Guru

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.

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

For some reason this is not working

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn