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

Alexander Grisb
Kilo Guru

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

Uncle Rob
Kilo Patron

Docs seems to think hasRole is singular and hasRoleFromList can evaluate multiple.

phantom7
Giga Expert

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

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