- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 11:34 AM
Greetings all,
Please provide guidance on the best way for me to locate all employees without any roles assigned:
I tried the below, but nothing came up:
My goal is to locate all employees without Roles:
cmdb_read
service_viewer
Cheers 🙂
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 11:48 AM
Hi Leon,
You can use the below background script to retrieve all the user's name with no roles.
var user = new GlideRecord('sys_user');
user.query();
while(user.next())
{
var userRole = new GlideRecord('sys_user_has_role');
userRole.addQuery('user',user.sys_id);
userRole.query();
if(!userRole.next())
{
gs.print('User Name : ' + user.name);
}
}
Thanks!!
Ram.
Please mark this as Helpful/Correct

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 11:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 11:57 AM
Please use the below background script to get the users without the role cmbd_reader and service_viewer
var user = new GlideRecord('sys_user');
user.query();
while(user.next())
{
var userRole = new GlideRecord('sys_user_has_role');
userRole.addQuery('user',user.sys_id);
userRole.addEncodedQuery('role=ab250967b31213005e3de13516a8dc26^ORrole=e70eac1d3be31300bc1e832b44efc47c');
userRole.query();
if(!userRole.next())
{
gs.print('User Name is(No role) : ' + user.name);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 11:57 AM
Please use the below background script to get the users without the role cmbd_reader and service_viewer
var user = new GlideRecord('sys_user');
user.query();
while(user.next())
{
var userRole = new GlideRecord('sys_user_has_role');
userRole.addQuery('user',user.sys_id);
userRole.addEncodedQuery('role=ab250967b31213005e3de13516a8dc26^ORrole=e70eac1d3be31300bc1e832b44efc47c');
userRole.query();
if(!userRole.next())
{
gs.print('User Name is(No role) : ' + user.name);
}
}