How to get list of user who have only ITIL role?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 07:41 AM
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?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 07:53 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 09:17 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 07:53 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 09:23 AM
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.