Creating a new parent group and need to move several groups currently under a different parent group

rita_m
Tera Guru

Hi!

 

I've been requested to create a new parent level group and to move several groups (currently under another parent group) to be under this new group instead.

 

Because all these groups have roles and inherited roles and roles inherited from parent groups and LOTS of users in each, etc, I cannot move all the groups at from one parent to another via list view; it will time out and only change a maybe 3 of the groups I need to move.  There are dozens of groups, and moving even just one takes a few minutes.

 

Is there a better way to handle this?  I know I can run a fix script or backout script to avoid the time out, but it'll still take several hours.  

 

Any suggestions welcome!

Thanks,

-R

1 ACCEPTED SOLUTION

Vaishnavi Lathk
Mega Sage
Mega Sage

Hello,

 

// Define the parent group sys_id to move groups under
var newParentGroupId = 'new_parent_group_sys_id'; // Replace with your new parent group sys_id

// Query for groups under the current parent group
var groupGR = new GlideRecord('sys_user_group');
groupGR.addQuery('parent', 'current_parent_group_sys_id'); // Replace with the current parent group sys_id
groupGR.query();

// Update each group's parent group to the new parent group
var count = 0;
while (groupGR.next()) {
groupGR.parent = newParentGroupId;
groupGR.update();

count++;
gs.info('Updated group ' + groupGR.name + ' (sys_id: ' + groupGR.sys_id + ')');
}

gs.info('Completed updating parent groups. Total groups updated: ' + count);

 

Replace 'new_parent_group_sys_id' and 'current_parent_group_sys_id' with the actual sys_ids of your new parent group and current parent group, respectively.

 

Regards,

Vaishnavi

 

View solution in original post

3 REPLIES 3

Vaishnavi Lathk
Mega Sage
Mega Sage

Hello,

 

// Define the parent group sys_id to move groups under
var newParentGroupId = 'new_parent_group_sys_id'; // Replace with your new parent group sys_id

// Query for groups under the current parent group
var groupGR = new GlideRecord('sys_user_group');
groupGR.addQuery('parent', 'current_parent_group_sys_id'); // Replace with the current parent group sys_id
groupGR.query();

// Update each group's parent group to the new parent group
var count = 0;
while (groupGR.next()) {
groupGR.parent = newParentGroupId;
groupGR.update();

count++;
gs.info('Updated group ' + groupGR.name + ' (sys_id: ' + groupGR.sys_id + ')');
}

gs.info('Completed updating parent groups. Total groups updated: ' + count);

 

Replace 'new_parent_group_sys_id' and 'current_parent_group_sys_id' with the actual sys_ids of your new parent group and current parent group, respectively.

 

Regards,

Vaishnavi

 

Hi @rita_m 

 

hope you are doing well

 As you are saying there are many users and also roles associated with these groups, it is very likely and expected to consume time, however to reduce the time and performance impact, we can have a different ondemand scheduled jobs logically bifurcated and created and assign different nodes(primary nodes)  to both of them in sys_trigger table and run them so system will not take consume much time as it is using two different nodes by distributing load.

 

regards,

swapnil

Hi Vaishnavi - 

I was able to update your script to only change those groups that I was requested to (rather than all), and set it as a fix script to be able to keep a close eye on the progress workers.  

 

This did what I needed. 

Much thanks,

-Rita