Add role to every user

Adds a role to every user.

Prerequisites

Note: This functionality requires a knowledge of JavaScript.

Role required: admin

In this sample, the role being added is Self Service. To add a different role, simply substitute the desired role for self_service.

Name: Add Role to Every User

Type: Client Script, Background Script

Table: sys_user

Description: Adds a role to every user. In this sample, the role being added is Self Service. To add a different role, simply substitute the desired role for self_service.

Parameters:

Script:

var gr = new GlideRecord("sys_user");
gr.query(); 
while(gr.next()) { 
   if (gr.accumulated_roles.toString().indexOf(",self_service,") == -1) {
    gr.roles = gr.roles + ",self_service";
    gr.update(); 
  } 
}