g_user.hasRoles() vs. g_user.hasRoleFromList
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2020 12:42 PM
I'm trying to determine when, or why, you would want to use one of the above methods over the other. From what I can gather from the GlideUser documentation, both of the above methods can check for multiple roles.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2020 06:14 PM
Hi,
g_user.hasRoles():
I believe it evaluates if the current user has any role whether it's 'Department','Division' or any other role. If the user has any role other than 'Department','Division' roles it should return true.
g_user.hasRoleFromList: (from ServiceNow docs)
Returns true if the current user has at least one of the specified roles or has the admin role.
Example from ServiceNow docs:
var isOK = g_user.hasRoleFromList("itil, maint, snc_internal", true);
Please mark it as helpful (or) correct if it helpful.
Thanks,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2020 06:22 AM
Thanks for the initial responses — I made a mistake in the initial request. The request should have been between g_user.hasRole() which takes a string and g_user.hasRoleFromList.