Can you add users to Groups with script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2009 11:50 AM
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.
- Labels:
-
Orchestration (ITOM)
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2018 09:50 AM
Hi Mark ,
Thanks,
I did the same for adding users to group via background script, it's showing records inserted in table ( sys_user_grmember ) and also showing from User table ( Related Link Group tab is showing the added group )
But , when we open group itself , it's not showing added Group Members.
Thanks,
Ashish
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 12:13 AM
I have a form. Include fields User, Department, Company, Group, referenced from tables sys_user, department, comoany and sys_user_group. when I select user, fields department company and group will automatically show the data. Then I change fields group and submit. I want after submit, the user's group will be changed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2018 03:00 AM
Hello Mark,
Can we add users to multiple groups?
Suppose we have List collector field on form referring to group table and if user needs to be added into multiple groups , multiple group names will be selected in this list collector field.
In this case ,how we can add user to all groups mentioned in list collector field?
Thanks
SD

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2018 05:06 AM
That is possible as well. With a list of string values, you just need to iterate through them using a 'for' loop instead of a GlideRecord query and 'while' loop.
var myGroups = current.variables.LISTCOLLECTORVARNAME;
// Iterate through groups in the list collector and add user to them
for (var group in myGroups) {
//Create a new group relationship record for this user
var rec1 = new GlideRecord('sys_user_grmember');
rec1.initialize();
rec1.user = USERRECORDORVARIABLE_WITH_SYS_ID;
rec1.group. = group; // Assumes group list collector references the 'sys_user_group' table
rec1.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2019 05:42 AM
Hi ,
I have a requirement where i need to add the user to a groups via workflow. The field in the catalog item Groups(sys_user_group) is of type (list collector).another
The field in the catalog item user(sys_user) is type reference.when i select 2 groups and one user then each group manager approve request then only the user will add the group
Is it possible to add the user to the groups via workflow? If yes, Please help me with the script.
Thanks,