- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2018 03:44 PM
Running code below in a client script on form, not on a record producer. The user has no Department or Division role, but does have a Unit role.
alert ("Starting");
var gUser = g_user.userID;
var Reviewer = g_user.hasRoles('Department','Division');
var personalRole = g_user.hasRole('Unit');
alert ("User: " + gUser + " Reviewer: " + Reviewer + " Unit Role :" + personalRole);
The last alert is showing the correct user (when I impersonate them).
Reviewer is ALWAYS true, even though the user doesn't have those roles.
The personalRole is correct and has been tested for both true and false conditions.
Any idea why it isn't returning false for Reviewer?
I've confirmed the user doesn't have either role (twice).
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2018 03:53 PM
g_user.hasRoles(); I believe it evaluates if current user has ANY role whether it's 'Department','Division' or ANY other role. If user has any role other than 'Department','Division' roles it should return true.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2018 03:56 PM
Reference https://www.servicenowguru.com/scripting/user-object-cheat-sheet/
g_user.hasRoles() | True if the current user has at least one role specified, false otherwise. Usage: g_user.hasRoles('itil','admin') |
Are you sure, user doesn't have any one role of Department or Division?
Also try using g_user.hasRole instead of g_user.hasRoles to verify those roles individually.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 06:44 PM
You can watch this video to get 100% working of function.