Script to Add Role to Existing Role?

J Benson
Tera Contributor

Good Morning Experts,

 

We have a requirement to add a new role to an existing role. The issue is the existing role already has 130K+ users inheriting it, so when attempting to add the new role via UI it updates 10K users at a time and then times out. The role then doesn't appear in the 'contains role' list for the existing role (I assume because it wasn't successfully applied to all users). 


I'm thinking this might be easier to do via background script. Does anyone have a script for such a task?

 

Thanks in advance,

James B

1 ACCEPTED SOLUTION

RaghavSh
Kilo Patron
var addRole = new GlideRecord('sys_user_role_contains');
addRole.initialize();
addRole.role = 'sys_id of parent role';
addRole.contains = 'sys_id of new role';
addRole.insert();

Raghav
MVP 2023

View solution in original post

4 REPLIES 4

RaghavSh
Kilo Patron
var addRole = new GlideRecord('sys_user_role_contains');
addRole.initialize();
addRole.role = 'sys_id of parent role';
addRole.contains = 'sys_id of new role';
addRole.insert();

Raghav
MVP 2023

Worked perfectly. Thank you so much for your help.

 

James B.

Along the same idea, can I get help adding a custom role to ALL users? The role is pm_user and needs added to all users. 

Amol Pawar
Tera Guru

Hi @RaghavSh ,

How can I give a role to all members of a group by script in one go?

If you could provide a script for this, it would be helpful for me.

Thanks,

Amol