Check if a user for a given userID has snc_internal role from scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 09:53 PM
In global application scope, we can check if a user has a role using the below API:
new GlideUser().getUserByID(userId).hasRole(roleName)
But for scoped applications, i'm not able to find a similar method. For a given userID and in my application scope, i want to check if it has snc_internal role or not?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 10:01 PM
Hi @DILEEPKUMAS7622 ,
You can query the sys_user_has_role table to retrieve a list of roles for the user.
Sample Code:
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user.user_name', gs.getUserDisplayName());
gr.query();
while(gr.next())
{
gs.addInfoMessage(gr.role.name); //prints the role name
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 10:08 PM
Yeah, that is the last option and i would not want to hit the DB directly. If you see in global scope, the methods like new GlideUser().getUserByID(userId).hasRole(roleName) rely on cache and fetch the data from cache. I'm looking for a somewhat similar approach
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 10:24 PM
why not use gs.hasRole('roleName')
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2025 09:40 PM
gs.hasRole() just checks for current user i guess. I want to check, for a given userID, does it have snc_internal role or not