- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2022 05:18 AM
How to list out the users with no roles just like (Abel Tuter) in servicenow Learning Platform?
Solved! Go to Solution.
- Labels:
-
User Experience and Design

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2022 05:25 AM
Hello Tejas,
you can use the below fix script to get the users list who do not have any roles
var gr3 = new GlideRecord('sys_user');
gr3.query();
while(gr3.next())
{
var gr2 = new GlideRecord('sys_user_has_role');
gr2.addQuery('user',gr3.sys_id);
gr2.query();
if(!gr2.next())
{
gs.print('User Name is(No role) : ' + gr3.name);
}
}
Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg
Regards
Sulabh Garg

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2022 11:01 PM
Hi Tejas, I see you have marked the other response as correct, Did you face any issue with this script?
Can you please mark my response as correct, If applicable. Thanks
Regards
Sulabh Garg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2022 11:48 PM
Done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2025 09:52 AM
You can improve it by adding the addActivequery
var gr3 = new GlideRecord('sys_user');
gr3.addActivequery()
gr3.query();
while(gr3.next())
{
var gr2 = new GlideRecord('sys_user_has_role');
gr2.addQuery('user',gr3.sys_id);
gr2.query();
if(!gr2.next())
{
gs.print('User without roles name : ' + gr3.name);
}
}