- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 05:51 AM
answer = true;
} else {
answer = false;
}
We also looked into the "High-Security Settings' plugin and set the 'glide.security.admin.override.accessterm' system property to 'true', but this did not work either.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 06:30 AM
Hi Tim,
After Aman's answer, I just realized that hasRoleExactly is not available at server side script.
You could try below script instead,
var grRole=new GlideRecord("sys_user_has_role");
grRole.addEncodedQuery("role=79f6671b0a0a0b8f00481621488887ff^user="+gs.getUserID()); //79f6671b0a0a0b8f00481621488887ff -> change this sys_id with pd_admin role sys id, I would suggest to store this sys_id in system proeprty and access it here as using hrd coded sys_id is not servicenow best practice.
grRole.query();
if(grRole.next()){
answer=true;
}else{
answer=false;
}
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 06:03 AM
Hi Tim,
The condition 'gs.hasRole('pd_admin')' always returns true for admin users that is the reason your script is failing.
Please try below code instead,
if(gs.hasRoleExactly('pd_admin')) {
answer = true;
} else {
answer = false;
}
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 06:30 AM
Hi Tim,
After Aman's answer, I just realized that hasRoleExactly is not available at server side script.
You could try below script instead,
var grRole=new GlideRecord("sys_user_has_role");
grRole.addEncodedQuery("role=79f6671b0a0a0b8f00481621488887ff^user="+gs.getUserID()); //79f6671b0a0a0b8f00481621488887ff -> change this sys_id with pd_admin role sys id, I would suggest to store this sys_id in system proeprty and access it here as using hrd coded sys_id is not servicenow best practice.
grRole.query();
if(grRole.next()){
answer=true;
}else{
answer=false;
}
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 07:09 AM
This does the trick! I thought I had done something similar before, but didn't have it working. This definitely works though. Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 06:14 AM
Hey,
Understood your query.
This is the limitation/challenge with hasRole function. This could be fixed be fixed usign hasRoleExactly(), but that can only be used in client side.
My recommendation would be to create your own script, which check "sys_user_has_role" table for checking if the user explicitly has 'pd_admin' role assigned to it, doesn't matter admin or not.
Aman Kumar