- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
can anyone please tell me why gs.hasRole('anyrole') is giving true for the admin and not for the other and also how to override this case that it must apply for admin too can we actually do that ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi @Jagadeesh_Maddi ,
yes it's returns true for admin even when the role doesn't exist and it's the expected behaviour
GlideSystem - Global--> User has at least one of the passed-in roles. Also returns true if the user has the administrator role.
to check if the user actually have the role you can use this
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago - last edited 7 hours ago
Admin has other roles too so it returns true.
Server side we don't have gs.hasRoleExactly hence this cant be used.
Here is community answer which can be used as workaround:
Thanks and Regards,
Mohammed Zakir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
Hi @Jagadeesh_Maddi,
because hasRole() is not evaluating whether it is directly assigned or inherited...
if you will use hasRoleExactly('yourRole'); then it will most likely be false, unless it is assigned manually or from group membership and not inherited from having admin...
Let me know if that worked for you
No AI was used in the writing of this post. Pure #GlideFather only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
admin inherits every role and hence it gives you true
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi @Jagadeesh_Maddi ,
yes it's returns true for admin even when the role doesn't exist and it's the expected behaviour
GlideSystem - Global--> User has at least one of the passed-in roles. Also returns true if the user has the administrator role.
to check if the user actually have the role you can use this
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago - last edited 7 hours ago
Admin has other roles too so it returns true.
Server side we don't have gs.hasRoleExactly hence this cant be used.
Here is community answer which can be used as workaround:
Thanks and Regards,
Mohammed Zakir
