How to get list of user who have only ITIL role?

Santosh Kallim1
Giga Contributor

Hello Experts,

 

I have 20K user's, there multiple roles added to each user's

There are some user's, only have ITIL role, there are no roles added to these users except ITIL, so I need to get the count of those users and sys_id through scripting, 

 

can anybody help me please? 

15 REPLIES 15

Ct111
Giga Sage

Check this 

 

var cnt=0;


var grUserRoles = new GlideRecord('sys_user_has_role');


grUserRoles.addQuery('role', '282bf1fac6112285017366cb5f867469'); // itil


grUserRoles.query();


while(grUserRoles.next()) {


cnt++


gs.print(grUserRoles.getDisplayValue('user'));


}


gs.print(cnt);

 

Mark my ANSWER as CORRECT and HELPFUL if it helps

This will revert overall count of users... but I want user who have only ITIL role,

example:

10users have roles, ITIL, chat_admin, pa_veiwer

and

15 users have alone ITIL role...

 

when run the above script I will get answer as 25,

But I trying to achieve it should revert only 15 bcz these 15 users has no role except ITIL.

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Santosh,

Try with script below.

var roleGr = new GlideRecord('sys_user_has_role');
roleGr.addQuery("role.nameSTARTSWITHitil^role.name!=admin");
roleGr.query();
while(roleGr.next())
{
var cnt = roleGr.getRowCount();
var userSysId = roleGr.user;

}

- Pradeep Sharma

 

This will revert overall count of users... but I want user who have only ITIL role,

example:

10users have roles, ITIL, chat_admin, pa_veiwer

and

15 users have alone ITIL role...

 

when run the above script I will get answer as 25,

But I trying to achieve it should revert only 15 bcz these 15 users has no role except ITIL.