- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2014 10:49 AM
On one of my test instances where I'm logged in as admin so I can execute code in the "Scripts - Background" window, I'm seeing odd results related to roles. If I run this:
var user = gs.getUser(); gs.print(user.getFullName()); gs.print(user.getFirstName()); gs.print(user.hasRole('There is no possible way this is a real role'));
I get the correct names printed, but then line 4 returns true. Doesn't matter what I put there, it just always says true. I'm trying to determine whether the current user has the Request Manager role in a specific service.
Solved! Go to Solution.
- Labels:
-
Service Mapping
- 7,000 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2014 11:09 AM
Hi Scott,
gs.hasRole() returns 'true' all the time for an Admin user. http://wiki.servicenow.com/index.php?title=GlideSystem#hasRole.28String.29
If you want to check for a role and make sure that an admin isn't looking at the record, you can use a condition like
gs.print(user.hasRole('some_role') && !user.hasRole('admin'));
Hope that helps.
Mandar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2014 11:09 AM
Hi Scott,
gs.hasRole() returns 'true' all the time for an Admin user. http://wiki.servicenow.com/index.php?title=GlideSystem#hasRole.28String.29
If you want to check for a role and make sure that an admin isn't looking at the record, you can use a condition like
gs.print(user.hasRole('some_role') && !user.hasRole('admin'));
Hope that helps.
Mandar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2014 11:38 AM
As Mandar said, admin users have every role by default, even made up roles. This was an issue for me when I was at an old employer and trying to restrict a field from everyone except for a set of users (accounting field). In the end, accounting just had to accept that we could see the role and trust us not to do anything with the info.