The CreatorCon Call for Content is officially open! Get started here.

Adding roles in bulk

jared_wentzel
Kilo Contributor

I'm trying to add a role to all users who have a certain value for company. So I found the following wiki page script and I am trying to modify it but first of all I'm not sure where to put it for a one time on demand run. I trying putting in in a scheduled job, and a client script with no dice...

http://wiki.servicenow.com/index.php?title=Useful_User_Scripts

And here is my script...

var gr = new GlideRecord("sys_user");

gr.addQuery('company', 'Fulbright & Jaworski L.L.P.');

gr.query();

while(gr.next()) {

  if (gr.accumulated_roles.toString().indexOf(",us_users,") == -1) {

    gr.roles = gr.roles + ",us_users";

    gr.update();

}

1 ACCEPTED SOLUTION

company is a related record on the user form so you will need to use the sys_id of the company



change


gr.addQuery('company', 'Fulbright & Jaworski L.L.P.');




to




gr.addQuery('company', 'sys_id of the company');


View solution in original post

20 REPLIES 20

marcguy
ServiceNow Employee
ServiceNow Employee

I think accumulated roles is an old legacy field that doesn't do anything anymore. Marc