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

Ahmer Faraz1
Tera Contributor

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

3 REPLIES 3

Tony Chatfield1
Kilo Patron

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.

Shaikh Rameez
Giga Expert

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

Gaurav Shirsat
Mega Sage
Hello
To assign a role to a User, use the Application Navigator in the main ServiceNow browser window (not Studio) to open User Administration > Users. Open a User record from the list.
  1. Select the role to add from the Collection slushbucket
  2. Select the role to add by clicking it.
  3. Use the Add button
  4. 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.

Add 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

Link

Please Mark Correct and Helpful

Thanks and Regards

Gaurav Shirsat