How to get users having only ITIL role but not admin role

ajay konduru
Tera Contributor

How do I get users who have only ITIL role but not any other role like admin role?

10 REPLIES 10

I just need to know a user who has an ITIL role but not Admin role since when I am testing some functionality I need to impersonate that ITIL person ...wish I could find a best way to get that person handy Everytime I test a scenerio .

Hi...

You can simply create a test user with ITIL role? That's usually pretty standard?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Jaspal Singh
Mega Patron
Mega Patron

Hi Ajay,

 

You can simply get a report created on User Roles (sys_user_has_role) table & do a Group by: Role to get the count. Additionally, if you are looking for script try something as below in background script.

var roleis;
var rolecount;
var count = new GlideAggregate('sys_user_has_role');
count.addEncodedQuery('role=282bf1fac6112285017366cb5f867469^ORrole=2831a114c611228501d4ea6c309d626d'); //Comment this line if required to see difference in result as it would give you result of itil & admin
count.addAggregate('COUNT','role');
count.query();
while(count.next()){
 roleis= count.role;
 rolecount= count.getAggregate('COUNT','role');
 gs.print("There are currently "+ rolecount+" users with a role of "+ roleis.getDisplayValue()); 
}

How can I get the first active user who has ITIL role alone ...not any roles

Hi Ajay,

 

There isn't any direct way to check that but if you want you can do a comparison by use of below script. That checks for Approvers who has ITIL role as well. Result is the overlapp. Try using it in background script.

var x=[];
		var countisss;
		var usritil;
		var usrr='';
		var usr=[];
		var usr_arr=[];
		var countiss=0;
		var usrrole=new GlideRecord('sys_user_has_role');
		usrrole.addQuery('role','debab85bff02110053ccffffffffffb6');//approver role
		usrrole.query();
		while(usrrole.next())
			{
			usr=usrrole.user+','+usr;
			
		}
		
		usr_arr=usr.split(',');
		for(var i=0; i<usr_arr.length;i++)
			{
			
			var strinuser=usr_arr[i].toString();
			usritil=new GlideRecord('sys_user_has_role');
			usritil.addQuery('role','282bf1fac6112285017366cb5f867469');//itil
			usritil.addQuery('user',strinuser);
			usritil.query();
			while(usritil.next())
				{
				countiss++;
				x.push(usritil.sys_id);
				
			}
		}
		
		gs.print('ITIL is '+countiss);