Hello all,
in my case I have an array which contains several hundred objects.
Each object contains a name, email and a task.
With a select I collect all emails and then I go into an apply to each in which I use a union to only get the emails once.
I then filter the big array to check if the email is equal to the current apply to each item and if yes, I am writing an Email to the user, telling him how many tasks are within the array (using length).
So far, so good.
Now I would also like to pull the name from the array so that I can address the Mail correctly ("Hello [Name]").
I tried to use item(Filter_array)?['Name'], however, this is not working. The Filter array has the big array containing all objects as the input.
Any ideas how I can pull the name into the Mail?
I suggest you do it slightly differently. Run the union outside of the array, this will give you a unique list of names and email addresses. Then inside your loop you can easily access the name:
Image of example flow here (for easier viewing)
Image:
See if that method is helpful to you.
Blog: tachytelic.net
YouTube: https://www.youtube.com/c/PaulieM/videos
If I answered your question, please accept it as a solution 😘
Thanks to both of you for replying so quickly!
Seems like I did not explain my case clear enough, sorry for that!
So the big array does not contain unique names. Many people appear several times as they have many tasks.
Therefore, I am using the union function inside the apply to each which then only contains the emails.
[
{
"Name": "Bob",
"Email": "bob@mailexample.com",
"Task": "Prepare the Excel sheet",
"Importance": "High"
},
{
"Name": "Will",
"Email": "will@mailexample.com",
"Task": "Update the presentation",
"Importance": "Low"
},
{
"Name": "Bob",
"Email": "bob@mailexample.com",
"Task": "Set up a meeting",
"Importance": "Low"
}
]
This example shows that Bob has two tasks.
So outside the apply to each I have a select collecting all emails from that array as this is the unique identifier.
As I need to only send one mail per user, I need a union, which is what is used within the apply to each.
In the following screenshot you can see the working flow.
FilterArticles contains all objects
Select Email filter out the email addresses ob the big array
union within the apply to each outputs the unique addresses
FilterMailCheck compares the big array with the current item
HTML Table pulls additional information which is shown in the email
All of this works.
The only thing missing is the user name which I would like to use to personalize the Mail 🙂
I hope it is better explained now, please excuse the confusion.
Kind regards
Markus
Hello @Markus44,
Your scenario is certainly a common one when working with arrays in Power Automate. If I understand your use case correctly, you're trying to access the 'Name' property within each item of your filtered array to personalize the emails.
I believe the expression items('Apply_to_each')['Name'] should work in your case. This expression will access the 'Name' property of the current item in the 'Apply_to_each' loop.
Also, based on your explanation, it seems like you are already using the Union() function to obtain unique emails. If so, you might not require the filter array action to filter emails. You can directly use items('Apply_to_each')['Email'] to fetch the email.
Here's a simplified example:
This should fetch the name of the current item in the loop, and the length function will return the number of tasks for the individual.
Please try this approach and let me know if it works for your scenario or if you encounter any issues or if i did not understand the requirement correctly 🙂
Hi @Markus44
It seems you're in the right path. In Filter array you should use:
- From: variable containing all the data
- expression: item()['Email'] is equal to items('apply_to_each')
Hope it helps!
Ferran
WarrenBelz
146,745
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,091
Most Valuable Professional