- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 12:22 AM
Hi,
We know that g_user.hasRole('itil'); will return true if user has itil role or admin role. Similarly does, gs.hasRole('itil'); works the same or does it return true only when user has itil role.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 12:25 AM
Hi @Sachin G K1 both method works the same, the difference is
g_user.hasRole() // client side call
gs.hasRole() // server side call
you could also use gs.hasRoleExactly()// it will check for admins as well
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 12:46 AM
Hi @Sachin G K1 you can use below code to check for admins in server side, this will return false if admin donot have itil role
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 12:27 AM
Hi both are different one is client side other one is server side
g_user.hasRole('itil'); its client side
gs.hasRole('itil'); its server side for more understanding check below link
https://blog.snowycode.com/post/user-object-cheat-sheet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 12:32 AM
Hi Harish,
Thanks for response, i went through the link you shared. Please have a look at picture i found there. My queries is simple, does gs.hasRole('itil'), will this return true if user doesn't have itil role but has admin role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 12:44 AM
Hi @Sachin G K1 ,
g_user.hasRole('itil') >> Returns true if the current user has the specified role or the admin role.
gs.hasRole('itil') >> Return true if the current user has at least one of the passed-in roles. Also returns true if the user has the administrator role.
For more information, you can refer below URLs:
1. https://developer.servicenow.com/dev.do#!/reference/api/utah/client/c_GlideUserAPI
2. https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideSystemAPI
Please hit the like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.
Thanks & Regards
Jyoti Jadhav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 12:52 AM
Hi @Sachin G K1
g_user.hasRole('itil') & gs.hasRole('itil') will return true if the user has itil role or admin role.
Both of them work similarly as g_user.hasRole() is on the client side & gs.hasRole() is on the server side.
Please mark it helpful, if the answer assists in resolving your question.
Best Regards,
Vaibhav Nikam
If my response finds helpful, please indicate its helpfulness by selecting Accept as Solution and Helpful.
Thanks,
Vaibhav Nikam