In Flow Designer, how do I email multiple admins when the article status changes to “xxxx”

鳴鏑張
Tera Contributor

I'm working on a Flow Designer flow that needs to send a notification email to multiple administrators when a article status changes to "xxxx"

 

Current Flow Structure 
1. Trigger: Record Created (xxxx table)
  Condition: Status is 'xxxx'

2. Look Up Records: Get group members from sys_user_grmember

3. If: Check if group has no members (record count = 0)
└─ then4. Send Email: Notify "updated by" user that email was not sent
5. Else: If group has members
└─ 6. For Each: Loop through group members
     └─ 7. Look Up Records: Get user details for each member
     └─ 8. For Each: Loop through user details
         (Trying to collect users who meet BOTH conditions here)
9. Send Email: Send to collected addresses (OUTSIDE all loops)

The flow needs to send email to users who meet BOTH conditions:
1. User is a member of the group (from step 2)
2. User belongs to the same "create team" group as the "updated by" user

That's why step 7 (Look Up Records) is needed - to filter users by checking if they belong to the same team as the updated by user.

Important Constraint
- Cannot use group email address
- Must send to individual user email addresses
- That's why we need to collect individual emails from qualifying users

 

Problem 1: At 8. For Each: Loop through user details. Only the latest user is collected, not all users

Problem 2: Data Pills Not Available
In Step 9 (Send Email - outside all loops), I cannot access the Data Pills from Step 8 (inside the For Each loop)
- The Data Pill picker does not show data from inside the For Each loops
- Cannot reference loop iteration data outside the loop scope

4 REPLIES 4

JenniferRah
Mega Sage

You can put a script in the "Send to" field of the email action in your flow. I have used something like this:

 

var peeps = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', 'ff6f6520db3b7e4022d358d6dc9619ab'); //sys_id of your group
gr.addQuery('user.active', true);
gr.query();
while(gr.next()){
    peeps.push(gr.user.email.toString());
}
return peeps.join(', ');

 

Using this approach, you don't have to cycle through the list of users.

 

If you don't want to use a script, you can send an individual email to each user in your for each loop.

Hi Jennifer,

Thank you for your suggestion. Your “script in Send To” approach worked and helped me verify the direction quickly.

I finally moved to a Flow Variables-based implementation for maintainability, but your example was very useful as the baseline and for troubleshooting.

Really appreciate your help.

Edoardo M
ServiceNow Employee

Hi, Jennifer’s script is a great solution, but writing GlideRecord code inside a flow action often defeats the purpose of using Flow Designer. You can fix the scope issue and keep this entirely no-code by using Flow Variables. The following could be a way to bridge data from inside a loop to an action outside of it.

 

The Low-Code Build

  1. Initialize the Variable: At the top of your flow, use the Initialize Flow Variable action. Create a variable (e.g., v_recipient_list) and set the type to String.

  2. Collect in the Loop: Inside your "For Each" loop (Step 8), use the Append to Flow Variables logic. Map your user's email address to the v_recipient_list variable. This stacks the emails into a comma-separated string rather than overwriting them on every iteration.

  3. Send the Email: In Step 9, look at the Flow Variables section of your Data Pill picker. Your v_recipient_list will be available there. Drag that into the "To" field of your Send Email action.

This approach solves your scope problem because flow variables exist at the top level of the flow, making them accessible regardless of how many loops you dive into. It also keeps your logic visible to anyone else who has to maintain this later.

 

You can find the specific documentation for this logic here: Append to Flow Variables flow logic

 

Please mark it as helpful and accept it as a solution if it helps you in any way.

Hi Edoardo,

Thank you for the low-code Flow Variables approach — I implemented this pattern and it worked well.

I now collect user IDs in-loop, deduplicate into a flow variable, then resolve to emails after the loop and pass the final mail list to the Send Email “To” field.

This solved the scope/visibility issue and kept the flow easier to maintain. Thanks again for the clear guidance.