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

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

}

}