How to give the role to users in Bulk. (1000 Users present on user table ).??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2021 11:49 AM
How to give the role to users in Bulk. (1000 Users present on user table ).??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2021 11:57 AM
Hi, normal process would be to add the role to a group and then add the users to the group.
Using this process\methodology makes for easier reporting and future maintenance\management of the users. The Group > User slush-bucket will only return X number of records (depending on your configuration), but you can select all from the filtered list, add, and then refresh the filter without having to save\navigate away.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2021 10:36 PM
Hi Ahmer,
For this first you have to take the approval from manager to add the roles or from scrum master. And suppose if you want to give one role to all the users who are active we have to use background script for this:
As for the testing purpose I have taken the sys_id of role named "cmdb_read". You have to just replace it with your role sys_id.
var gr = new GlideRecord('sys_user');
gr.addQuery('active', true)
gr.query();
while(gr.next()) {
var grd = new GlideRecord('sys_user_has_role');
grd.user = gr.sys_id;
grd.role = 'ab250967b31213005e3de13516a8dc26';
//ab250967b31213005e3de13516a8dc26 - sys_id of cmdb_read
grd.insert();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2021 12:42 AM
- Select the role to add from the Collection slushbucket
- Select the role to add by clicking it.
- Use the Add button
- Click the Save button.
as per the Best Practice:-
What SN says is if you want to assign particular set of people to give them roles , better create a group and add a role to that group. So all the members in that group will be inherited with the role.
Hi If You want to Give Role to users of same company then they all should have same company field automatically.
so you can try this script:-
var gr = new GlideRecord("sys_user");
gr.addQuery('company', 'sys_id');// please add sys_id of the company
gr.query();
while(gr.next()) {
if (gr.accumulated_roles.toString().indexOf(",us_users,") == -1) {
gr.roles = gr.roles + ",us_users";
gr.update();
}
Refer the Threads
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat