- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 04:31 AM
I am working on Geneva version and I am trying to restrict admin override on ACL with the below script.
I intend to allow only users with "contact manager" role to view my field and restrict all others even if they are admin, I have unchecked admin override
I have tried the below two scripts, can someone help me figure out the glitch. Thanks Advance !!
// Allow access only if the contract manager role is present else restrict even if its admin.
if (gs.hasRoleExactly('contract_manager')) {
answer = true;
}
else {
answer = false;
}
and
// Allow access only if the contract manager role is present else restrict even if its admin.
if ((gs.hasRole('contract_manager') && gs.hasRole('admin')) || (gs.hasRole('contract_manager') && !gs.hasRole('admin'))) {
answer = true;
}
else if (!gs.hasRole('contract_manager') && gs.hasRole('admin')){
answer = false;
}
else {
answer = false;
}
Regards,
Heena Dahiya
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 06:11 AM
Hi Heena,
One of the unique things about the admin role is that hasRole() will always return true for admins whether they specifically have a role or not. You might try using gs.getSession().getRoles() which returns all roles for a user and then iterate through those in a script.
Getting a User Object - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 04:59 AM
Hi Heena,
Instead of writing code in script part, if you can try this:
remove the script and add the required role in the "Requires role"
and uncheck the "admin override".
PS: Hit answered, like, Helpful or Correct depending on the impact of the response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 05:05 AM
Hi Anupama,
That was the first thing I did, post that I tried this script. Apologies I forgot to mention that.
Though I appreciate you response
Regards,
Heena

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 06:11 AM
Hi Heena,
One of the unique things about the admin role is that hasRole() will always return true for admins whether they specifically have a role or not. You might try using gs.getSession().getRoles() which returns all roles for a user and then iterate through those in a script.
Getting a User Object - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 06:13 AM
Thanks Brad !! That was helpful.
Regards,
Heena