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 04:59 PM
The only thing I would be able to think of is it might take more processing power under the hood to parse through multiple lists with g_user.hasRoles(). Depending on how something is coded, it may be able to do something, but it might be faster. Another reason could be that one of these is a relic from an era where both were needed and the hasRoles() method become more common and popular so it was modified for that. There's not much telling on them. I would use whichever one you find preferential, or you could do a test with both of them in background scripts to see which is faster, although, it's probably negligible.
Hope this answer helped or solved your problem. If so, please mark as 'Helpful' or 'Correct'. Thanks!
Alexander
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2020 05:00 PM
Docs seems to think hasRole is singular and hasRoleFromList can evaluate multiple.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2020 05:01 PM
Hey alynch,
g_user.hasRoles() - Takes no arguments. Checks if the user has any role. will return false if the user has 0 roles and true if the user has 1 or more roles
g_user.hasRoleFromList() - Takes an array of roles as argument. Will return true if the user has any of the roles passed to the function.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2020 05:04 PM
Just to add that you can add a true to g_user.hasRoles(true); as argument, This will return true if the user does not have any of the default roles like snc_internal and snc_external. but I have never used it like this.
Thank you