Add users (from list collector field) to the group/s selected in a list collector field

ss123
Tera Contributor

Hi All

 

Can I ask how do we automate that when we select user/s (from list collector field), they will be automatically added to the group/s selected in a list collector field , after the group manager approval. Note: Using Flow Designer

 

Example:

List collector field name for the users: users_to_be_added

User_1, User_2, User_3

List collector field name for the groups: group_records

Help Desk, HR Group

 

Once the form is submitted in the portal, the group managers of Help Desk, HR Group needs to approve first, once they approve, User_1, User_2, User_3 will be automatically added on those groups.

 

Thank you.

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@ss123 

you can iterate using For each for that list collector and then add the user to individual groups

what did you start with?

OR

you can also use custom action in flow and pass the values for both the list collectors and then use script for this

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

Vishal Birajdar
Giga Sage

Hi @ss123 

 

You can try below steps :

 

Step 1: Trigger - Service Catalog

 

VishalBirajdar7_0-1695364980308.png

 

Step 2 : Action  - Ask for approvals

Put your group name as per your need

 

VishalBirajdar7_1-1695365062717.png

 

Step 3 : Add flow logic - If condition

To check if Its approved

VishalBirajdar7_2-1695365163318.png

 

Step 4 : Look up for user records from variable list collector (Users)

 

 

VishalBirajdar7_4-1695365260456.png

 

In condition , use script to get the "Users" list from variable // you can use your variable name

 

VishalBirajdar7_5-1695365321717.png

 

Step 5 : Use flow login - for each

This will iterate through users which we will get from step 4

 

VishalBirajdar7_6-1695365433473.png

 

Step 6 : Look up for Group records from variable list collector (Groups)

 

VishalBirajdar7_7-1695365503958.png

 

use the script in condition 

 

VishalBirajdar7_8-1695365544098.png

 

Step 7 : Use flow logic - for each

To iterate through each group

VishalBirajdar7_9-1695365672927.png

 

Step 7 : Use Action to create record in "sys_user_grmember" table

 

Use sys_id , from user & group record

 

VishalBirajdar7_10-1695365787816.png

 

Final flow should look like this 

 

VishalBirajdar7_11-1695365879332.png

 

Note : for the already existing group member, you can use script to check if user is already member of group and eliminate that from list of sys_id.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hi @Vishal Birajdar in 

Step 2 : Action  - Ask for approvals

Put your group name as per your need

 

The approval from the group managers are not  manually added in the flow, the groups are added by the requesters. So the group manager approval/s should be dynamic. Thanks

Hi @ss123 

 

1. You can add on "Look up records" ('sys_user' table)action before "Ask for approval" activity with script condition 

 

VishalBirajdar7_0-1695617669602.png

 

2. Condition Script : 

Here will will get the group managers sys_id form list collector (groups)

 

var groups = fd_data.trigger.request_item.variables.groups;

var managerArray=[];

var grGroups = new GlideRecord('sys_user_group');
grGroups.addEncodedQuery('sys_idIN' + groups);
grGroups.query();
while(grGroups.next()){
//get managers
managerArray.push(grGroups.getValue('manager'));
}
var managers = managerArray.join(',');
//return the sys_id of managers to lookup records
return 'sys_idIN' + managers;

VishalBirajdar7_1-1695617796142.png

 

3. Update the ask for approval activity

Drag n drop the user records from 1 look up record activity.

 

VishalBirajdar7_2-1695618032120.png

 

Final flow be like : 

 

VishalBirajdar7_3-1695618126677.png

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates