Loop through a group and capture email address in a flow variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello!
I'm trying to loop through a group and capture all email addresses of the people in that group. Here is what I've done that is not working:
1. Create a flow variable: u_approval_members (WORKING)
2. Use "Lookup Records" to loop through all members of a group (WORKING)
3. Create "FOR EACH" loop to cycle through the records found in #2 above. (WORKING)
4. Within the loop, use LOG INFO to show me the email address of each person it found (WORKING)
5. Within the loop, use "Set Flow Variable" using the script below to capture all the email addresses in the string I created in #1 (NOT WORKING)
var currentList = fd_data.flow_var.u_approval_members || ''; // Fallback to empty string
var email = current.user.email || ''; // Fallback to empty string
if (email) { // Only append valid emails
return currentList ? currentList + ',' + email : email; // Append with comma or start list
}
return currentList; // Return unchanged if no email
Any ideas? ?Thanks everyone!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello my friend. Your script appears to be the same one I originally posted so it does not work. I do think I found a solution below however.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @brianhofmei
I just modified the flow steps and script as below and got the desired output.
Please try this and see how it goes..
Set Flow Variable script:
var current_flow_variable_value = fd_data.flow_var.u_approval_members;
var arr =[];
if(str!=''){
arr.push(cuurent_flow_variable_value);
}
arr.push(fd_data._2__for_each.item.user.email.toString()); //STEP NUMBER MAY VARY
var mail_ids = arr.join(",");
return mail_ids;
Flow actions steps:
Output:
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Evening my friend! Your solution actually helped me identify the problem in my script. specifically this line:
arr.push(fd_data._2__for_each.item.user.email.toString()); //STEP NUMBER MAY VARY
I did not realize the correct syntax for calling the current record of a FOR EACH loop is:
fd_data_#__for_each
Here is the single line of code I was using and what I changed it to:
// Original
var email = current.user.email || ''; // Fallback to empty string
// New
var email = fd_data._7__for_each.item.user.email || ''; // Fallback to empty string
My original script works with just this change! I'm accepting your solution because you led me to the answer. Thank you!
Only follow-up question, is this bad practice to define the flow designer step number like this in a script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @brianhofmei
Glad it helped..
I wouldn’t call it a bad practice, because if you need to do some scripting, that’s often the only option available. However, wherever possible, try to use the oob features. Also, in the future, if you make any changes to your flow that impact the scripting, you’ll receive an error or warning message. So, you’ll need to review and resolve those issues accordingly