What is the difference "hasRoleOnly" and "hasRoleExactly"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2020 07:50 PM
What is the difference "hasRoleOnly" and "hasRoleExactly"?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2020 08:06 PM
hasRoleExactly
Returns true only if the current user has the specified role. let say hasRoleExactly('itil') it will check if the user has itil role and for admin user with no itil role it will return false. It is available on client side.
hasRole
Determines if the current user has the specified role. let say hasRole('itil') It will also return true for admin users regardless of the role specfied. It is available on server side.
Please mark this accepted and helpful if your question has been answered. Thanks!
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2020 08:20 PM
Hi Ss,
Adding to it You can use both the methods in client side and the difference would be:
g_user.hasRole('client_script_admin');
This script checks to see if the currently logged in user has the capability to create and edit Client Scripts (client_script_admin role). Note that this script returns true not only when the currently logged in user has the role assigned but also if the currently logged in user has the admin role. The admin user has all roles implicitly assigned.
To test whether the currently logged in user has the role explicitly assigned, use the hasRoleExactly() method:
g_user.hasRoleExactly('client_script_admin');
You can watch the video as well which explain the difference between all the methods of roles:
https://www.youtube.com/watch?v=5wVxjGXsEWY&feature=youtu.be
Please mark correct and helpful.
Thanks,
CB

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2020 08:37 PM
Hi,
Client Side:
1) g_user.hasRoleExactly()
Return true if current user has given role(g_user.hasRoleExactly('itil'); //here itil role is check only not other). whatever the role specified here this method is only work for single role not check if current user has another role. this method is available in g_user API which is at client side.
2)hasRole
True if the current user has the role specified, false otherwise. ALWAYS returns true if the user has the 'admin' role.
Usage: g_user.hasRole('itil')
Server Side
1) gs.hasRole('itil')
Returns true if the user has the given role, false otherwise.
if(gs.hasRole('itil')){ //Do something... }
2)gs.hasRole()
Returns true if the user has one of the given roles, false otherwise.
f(gs.hasRole('itil,admin')){
//If user has 'itil' OR 'admin' role then Do something...
}
3)gs.hasRoles()
Returns true if the user has any roles at all, false if the user has no role (i.e. an ess user).
if(!gs.getUser().hasRoles()){
//User is an ess user...
}
For your more understanding check below link
https://www.servicenowguru.com/scripting/user-object-cheat-sheet/
Please Mark Correct/Helpful answer if it help you in any way.
Thanks,
Kunal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2020 08:50 PM
Hey SS,
In addition to kunal's point,
The below link will give you the clear idea about the differences in gs as well as g_user objects.
https://www.youtube.com/watch?v=5wVxjGXsEWY&feature=youtu.be
Hope this helps!!!
Regards,
Namrata.