Can you add users to Groups with script?

gvanroy
Kilo Expert

We are working on addings users to groups based on a field we have for their region. For example all users in the Asia region would be added to the Asia Users group. I haven't seen a way to do this through the ui by picking the group and adding all users that meet the criteria to the group. I know it could be done via the list collector but it limits you to 100 people at a time and when dealing with 8k users its difficult. Because roles/groups are handled differently ie I can't filter from a list view and then update all with the information it would be nice if someone had a similar script to add mass users to groups/roles.

15 REPLIES 15

Tawseef
Tera Contributor
var groups = workflow.scratchpad.groups.toString().split(',');
//gs.log(groups.length);
for (var i = 0; i < groups.length; i++){
   var gr = new GlideRecord ('sys_user_grmember');
   gr.initialize();
   gr.group = groups[i];
   gr.user = current.variables.name.sys_id;
   gr.insert();
}