How to assign a role for very bulk users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2022 06:05 AM
HI Team,
We are having 3lakhs+ users in our environment.
We have a requirement to give a role for all users.
What is the feasible/best practice way?
Please suggest.
Thanks,
Sri

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2022 06:14 AM
Hi Sri,
If you want to give a role to all users then run the below background script.
Navigate to System Definitions > Scripts - Background
Run the below code
var gr = new GlideRecord("sys_user");
gr.query();
while(gr.next()) {
var role = new GlideRecord('sys_user_has_role')
role.addQuery('user',gr.sys_id);
role.addQuery('role', 'sys_id of the role'); //give sysid of role here
role.query();
if(!role.next())
role.initialize();
role.user = gr.sys_id;
role.role = "sys_id of the role"; //give sysid of role here
role.insert();
}
}
It will add role to all users in your instance.
But as a best practice you can give the role to a group and add all users to that group.
Mark as correct and helpful if it worked for you.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2022 06:16 AM
Hi Sri,
As a best practice it would be to adding the role to a group and then add the users to the group.
For Example :
Create a new group with the required role assigned
Then create a CSV file with the user names and the new group name
import the csv file to the sys_user_grmember table.
Here is a link to implement :https://community.servicenow.com/community?id=community_question&sys_id=3ab487e9dbd8dbc01dcaf3231f96...
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2022 12:41 AM
Hi Sri,
Any update to this ?Any follow-up required? if not
Kindly mark the answer as Correct & Helpful both such that others can get help.
Thanks,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2022 11:35 PM
Hi Sri,
The best way is simply
(Option 1)
1.) create a group
2.) Assign role to a group
3.) In User related list add all users to this group (Step 3 to 5 in option 2).
(Option 2 )Another way without creating group is to
1.) Open the form of the required role
2.) In the User related list click on edit
3.) Using ctrl+a select all users
4.) Shift them right in the bucket list
5.) Click on save.
(Option 3)
Well explained by Sumant in the first comment.
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful for you!
-Vijendra