The CreatorCon Call for Content is officially open! Get started here.

Identify users without any roles

Leon Els
Tera Expert

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:

 

LeonEls_0-1682532373727.png

 

My goal is to locate all employees without Roles:  
cmdb_read
service_viewer

Cheers 🙂 

 

3 ACCEPTED SOLUTIONS

Ramkumar Thanga
Mega Sage

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 

View solution in original post

DrewW
Mega Sage

If you are doing a report or going to the user table then just do

DrewW_0-1682534984452.png

 

View solution in original post

Ramkumar Thanga
Mega Sage

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);

}

}

View solution in original post

5 REPLIES 5

Ramkumar Thanga
Mega Sage

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 

DrewW
Mega Sage

If you are doing a report or going to the user table then just do

DrewW_0-1682534984452.png

 

Thank you SO much for your response!

Karan Chhabra6
Mega Sage

Hi @Leon Els ,

 

To get the list of users with no roles, use this filter condition: 
SysID   is not   javascript: getRoledUsers();

KaranChhabra6_0-1682535054234.png

 

If my answer has helped with your question, please mark it as helpful and accepted solution.

 

Thanks!