Moving group members - best method?

phenkry
Tera Contributor

In the example below, there are 200 members in Group A and 180 members in Group B. How would you best go about moving all the members from Group B to Group A? Resulting in 380 members in Group A and no members in Group B.

thx, Parker

find_real_file.png

1 ACCEPTED SOLUTION

Tommy SN Sahlin
Kilo Sage

Not a very sophisticated solution, but it's super-quick and it works:

  1. Go to Group B, set the related list for Group Members to only show the User ID column
  2. Select the whole list of User id's by dragging the mouse down, and copy (ctrl+c)
  3. Go to the Group A related list for Group Members, click the blue Edit button
  4. In the slushbucket form, add filter "User ID is one of" and paste the list of User IDs in the box, run the filter
  5. Now the first 100 users (if you haven't increased that limit) show up in the left slush bucket window. Move them to the right window.
  6. Run the filter again to get the next 100 users, move them to the right. Repeat until they are all added, and Save.
  7. Finally, go back to the slushbucket form for Group B and remove the users from that group.

cheers, hope that helps /Tommy

View solution in original post

5 REPLIES 5

eumak
Tera Guru

Hello @phenkry ,

Please run the below code in background script.

var grp = new GlideAggregate("sys_user_grmember");     
grp.addAggregate("COUNT");
grp.addEncodedQuery('---------------------');     // Your query condition
grp.groupBy("user");     
grp.query();     
while (grp.next()) 
{   
//gs.print(grp.user.name);

var rec1 = new GlideRecord('sys_user_grmember');   
   rec1.initialize();   
   rec1.user = grp.user;   
   rec1.group.setDisplayValue('------------'); // New group name   
   rec1.insert();
}
var pr= new GlideRecord('sys_group_has_role');
pr.addEncodedQuery('------------------') //;   Query condition to delete records
pr.query();
while(pr.next())
{
pr.deleteMultiple();

}




Cheers..!
Happy learning:)
Tushar 

Mark it as helpful or correct, If Applicable


Cheers..!

Happy Learning:)

Tushar

Adrian Ubeda
Mega Sage
Mega Sage

Hi phenkry,

I'll create a fix script for this and run it as need it. I let some code for achieving this:

var grGroupA = new GlideRecord('sys_user_grmember');
grGroupA.addEncodedQuery('group=' + sysIDGroupA);
grGroupA.query();

while(grGroupA.next()) {
    // Add user in group B
    grGroupB = new GlideRecord'sys_user_grmember');
    grGroupB.initialize();
    grGroupB.setValue('group', groupBSysID);
    grGroupB.setValue('user', grGroupA.user);
    grGroupB.insert();

    //Remove record from group A, check first if all Group A members are moved to Group B
    grGroupA.deleteRecord();
}

If it was helpful, please give positive feedback.
Thanks,

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

Ankur Bawiskar
Tera Patron
Tera Patron

@phenkry 

Easy approach which can be re-used later on

1) create data source and excel file

2) Have 3 columns like this

3) create transform map on sys_user_grmember table, 2 field maps and use onAfter transform script to delete that user from old group

This solution can be re-used later on; you just need to do this

1) go to sys_user_grmember table and filter with Group B and your users and export it

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

OlaN
Giga Sage
Giga Sage

Hi,

Kind of the same solution, but instead using Flow designer, which would require no coding at all.
Trigger on the Flow should be Once, at the date/time of your choice.

Steps 6-7 are optional if you want to perform some logging if a user already is part of group B.

Also, didn't include steps to delete the user from groupmembership A, but it can easily be added if necessary.

find_real_file.png