How to collect no. of users who have ITIL or Admin role in servicenow

bijender1
Tera Contributor

How to collect no. of users who have ITIL or Admin role in servicenow

9 REPLIES 9

vitaly_sukharev
Kilo Guru

Hi Bijender,



Alternatively, you can query sys_user table using 'Roles' attribute:


Capture.PNG


Encoded query is: roles=itil^ORroles=admin


bijender1
Tera Contributor

Hi All,



I think i find the solution, Please can you check and confirm if it is taking out the correct report.



find_real_file.png


That would work.



UPDATE 1:


If you add an OR-condition to handle the admin role as well of course.


Hi Bijender,



yes it will show correct number of user with "ITIL" role.



Regards,


Stefan


Harsh Vardhan
Giga Patron

if you need script here you go. i tested and it's working



count=0;


var grUserRoles = new GlideRecord('sys_user_has_role');  


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


grUserRoles.query();  


while(grUserRoles.next()) {


count++  


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


}


gs.print(count);




you can run into background script .



find_real_file.png