g_user.hasRoles() vs. g_user.hasRoleFromList

alynch
Kilo Contributor

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. 

6 REPLIES 6

Sumanth16
Kilo Patron

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

alynch
Kilo Contributor

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.