- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2016 04:24 PM
This is the script for adding roles to the user, which I copied from wiki. Can anyone explain what is accumulated_roles here and why we convert this to string?
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();
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2016 05:52 PM
Here is the script that will add self service role to all the active users
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 = '[sys_id of the role you want to add]'; // sys_id of self_service role
grd.insert();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2016 05:28 PM
Hey sorry. above script in updating the Roles field not the accumulated roles..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2016 05:33 PM
Ok I need to add self_service role to all the users, so how can I do that?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2016 05:46 PM
Can you explain us the business reason a little bit?
So that i can tell you if you need a script to achieve that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2016 06:06 PM
they want me to add the self_service role to the role table, so that when we edit the role, we can see that value in there

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2016 06:13 PM