I'm new to flow and would appreciate any input on the following:
Using one excel table I'm trying to send an email to my primary contacts based on a category they fall in. This category can multiple different secondary contacts and would need to cc all of them in a single email sending to the primary contact. Below is a general idea of what my flow looks like.
I keep getting errors in the cc field using expression: join(outputs('apply_to_each_3'),'; ')
I played around with it but keep getting error on how join must pull from an array.
Just looking for a general idea on how to go about this. Let me know if you'd like specific details.
Hi @rzaneti,
Thanks for your help but this didn't seem to solve the issue. This might provide more context:
This first apply to each and below expression pull the distinct secondary contacts based on the category. I then use the composed object in my second filter array. The "first" expression however only pulls the first email listed in the excel table that matches the category. Please note my primary and secondary contacts are separate lists. Also, power automate doesn't let me select secondary contacts from an array and says I need to use integer index.
first(body('Filter_array'))?['Secondary contact']
Hi @Anonymous ,
The variable may be initialized out of the 'Apply to each' block (and may be placed before it).
The expression will be item()['Secondary contact']. As you won't be initializing the variable inside the loop, Power Automate may not issue the error anymore.
What would the expression be then? there isnt an option to choose outputs of filter array and when I manually type one of these expression: outputs/body/item/items(filter_array_2)?['Secondary contact'], it says it cannot select the property and array elements can only be selected using inter index.
If i try to use item/items, i can't save because of below error. But when I try to add initialize variable to my apply to each loop, it says it must be on the top level. The i wouldnt be able to reference the filter array in my initialize variable because it is after it.
Flow save failed with code 'InvalidTemplate' and message 'The template validation failed: 'The workflow action 'Initialize_variable' at line '1 and column '10036' references the action 'filter_array_2' of type 'Query': only the actions of type 'foreach' are allowed to be referenced by 'repeatItems' or 'items' functions.'.'.
Hi @Anonymous ,
The solution above is to extract dynamic values. In your case you will just replace the 'source' variable for the array where you have the filtered Excel records stored (which seems to be 'Filter array 2').
Hi @Anonymous ,
Thank you for the additional clarification. Based on your description, we just need to extract the email property from a list of objects (which in this case is the output from 'Filter_array_2').
For this example, I'm using this array of objects (called 'source), from where we will extract the email and allocate in a string with a structure of 'email1; email2; email3', by using the semicolon as separator for each email address:
From your end, just replace the 'source' variable for your 'Filter_array_2'.
First, initialize a string variable with empty value. Here you will store the list of emails to be sent (the 'CCs'):
Then you can use an 'Apply to each' loop to access the array with the emails (which in your case seems to be the output from 'Filter array 2'), and insert an 'Append to string variable' action inside it, to populate the variable that you created in the previous step. In the value to be appended, insert the dynamic content of the 'Secondary contact' column from your 'Filter array 2' (in the example below, represented by the 'email' column, highlighted in blue). Finally, make sure to include a semicolon and a blank space after the dynamic content (highlighted in green):
The output from each loop iteration will look like this, matching to the email, the semicolon and a blank value.
After the loop, you will be able to access the text with all emails, but before it, we need to remove the semicolon and blank space at the end. So we will need to use the following expression: slice(variables('email_list'), 0, sub(length(variables('email_list')), 2)):
This expression will be basically remove the last 2 characters from the string, resulting in the following output:
Then you will be able to use it in your Email action 🙂
I'm not sure if it will solve your problem, but feel free to provide more details or bring any other challenges related to the flow.
Let me know if it works for you or if you need any additional help!
-------------------------------------------------------------------------
If this is the answer for your question, please mark the post as Solved.
If this answer helps you in any way, please give it a like.
Sorry for the confusion. Let me start from scratch.
The excel table I'm pulling from is a long list that has (from left to right): category, relevant info columns, primary contact email (individual), secondary contact email (individual)
from left pic to right pic:
I'm selecting by category and getting unique categories > apply to each to filter by category and create my html table I'm inputting into my email and also compose objects required to complete next steps > select 2 and compose distinct names selects primary contact, apply to each 2 filters primary contact and composes emails. In my cc field is: first(body('Filter_array_2'))?['Secondary contact'], however, this is only cc'ing the first secondary contact. How can i cc multiple respective secondary contacts that match with the excel rows I pull from? I've tried different routes but lack technical expertise to get it to work.
Hi @Anonymous ,
Sorry, but I'm not sure if I understood your process. Please, confirm if this is correct:
1. You pull all rows from your Excel table ('List rows present into a table' action)
2. You filter these records based on a primary contact/category column (in which action are you filtering it? Does it return only one record or more than one)?
3. After that, you use the 'Apply to each 3' loop, using the output from step 2 as input (1 or 'N' of records matching to a specific category/column).
4. You try to join all of the items from 'Apply to each 3', and this is where you are getting the error.
If you prefer, you can also share some screens of your actions in expanded view to illustrate the process.
Hi @rzaneti,
Thanks for the reply.
My cc column (secondary contacts) is just one email per row.
The apply to each 3 is to filter my secondary contacts based on primary contact/category. Any suggestions on how I can filter cc column and adding it to array so I can use the join function?
Michael E. Gernaey
497
Super User 2025 Season 2
David_MA
436
Super User 2025 Season 2
Riyaz_riz11
244
Super User 2025 Season 2