Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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?

11 REPLIES 11

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

		
	

Balaram4
Kilo Expert

Hi Ajay,

 

For achieving this 

Please create a report on (sys_user)table.

And use the below filter conditions.

Active is true and 

Roles is Itil and 

Roles is not admin.

And generate a report.

So that you will get all itil users list not admins.

 

 

Please mark this as correct answer or helpful if this really works for you.

 

 

Ty,

Balaram.