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.

Fix Script Role contains Roles, problem in views.

juancarrion
Tera Contributor

Hello Community, 

I have a problem in my current development that I couldn't crack.

1. I want to find all the users which has the view_changer role.
2. Problem is that view_changer role is contain in several roles, groups,etc.
Bottom line how can I find all the roles and group that contains view_changer role?

because thinking itil has the view_changer and admin has itil so at the end both admin and itil have the view_changer is there any easy way to do this on ServiceNow?


2 ACCEPTED SOLUTIONS

JenniferRah
Mega Sage
Mega Sage

I just ran this and it seemed to work:

var gr = new GlideRecord('sys_user');
gr.addActiveQuery();
gr.query();
var count = 0;
var x = gr.getRowCount();
var curuser = gs.getUser();
while(gr.next()){
	var user = curuser.getUserByID(gr.user_name);
	if(user.hasRole('view_changer')){
		gs.print("** " + gr.name + " has role");
		count++;
	}
}
gs.print("** Found " + count + " users out of " + x + " with role.");

View solution in original post

jcmings
Mega Sage

Find all roles that contain view_changer

Navigate to sys_user_role_contains.list and search for the role view_change

 

Find all groups that contain view_changer

Navigate to sys_group_has_role.list and search for the role view_change OR whatever roles you identified that contain the role

 

Find all users that have the view_change role

Navigate to sys_user_has_role.list and search for the role view_change OR whatever roles you identified that contain the role

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@juancarrion 

share the script you are using

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader