g_user.harRole() , g_user.hasRoleExactly() and g_user.hasRoles()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2018 02:23 AM
Hii folks
i am confused in g_user.harRole() , g_user.hasRoleExactly() and g_user.hasRoles() . what is exactly difference between this 3 methods?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2018 02:29 AM
Hi Vinayak,
All these three are used for checking whether the user has role are not with slight difference.
g_user.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')
g_user.hasRoleExactly():True if the current user has the exact role specified, false otherwise, regardless of 'admin' role.
Usage: g_user.hasRoleExactly('itil')
g_user.hasRoles():True if the current user has at least one role specified, false otherwise.
Usage: g_user.hasRoles('itil','admin')
Hope this clears you.
#Copied form this link:
https://www.servicenowguru.com/scripting/user-object-cheat-sheet/
Thanks,
Nithin.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2021 04:14 PM
https://servicenowguru.com/scripting/user-object-cheat-sheet/
see if this post helps:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 04:15 AM
g_user.hasRoles('itil','admin') is not a correct way to use.
hasRoles(Boolean includeDefaults)
Returns true if the current user has any role.
var yesRole = g_user.hasRoles();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2021 04:23 PM
The ServiceNow API is documented at developer.service-now.com, including g_user.
There is actually 4 methods:
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022