- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 08:07 AM
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?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 08:52 AM
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.");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 09:25 AM - edited 02-11-2025 09:26 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 08:52 AM
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.");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 09:25 AM - edited 02-11-2025 09:26 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2025 03:28 AM
Thanks a lot it was very helpful in my final solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 06:49 PM - edited 02-11-2025 06:50 PM
Hi @juancarrion ,
You need to fetch data from tables and then filter based on need.
Get the list of role(s) which contains this view_change role from table "sys_user_role_contains"
Get the list of User who has this role, either direct or through group and inherited & inheritence count will explain that. You will get the Contained By and Group both the count here.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution