web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Filter Array and Apply...
Power Automate
Answered

Filter Array and Apply to Each issue

(0) ShareShare
ReportReport
Posted on by 43
I have 2 SharePoint Lists.  A master list and a details list.  I am adding items to the lists via a PowerApp and that part works just fine.  When I add an item, it adds "main" information on the master list with the "ID" numeric field being populated by default.  Then on the second list I have detailed lines, and each line has a "MasterID" that is the same number as the ID field in the master list.  This is how I can tie them together.  For example, I add "Bucket" to the master list with ID of 12 and then red bucket, blue bucket and green bucket are added to the details list with the MasterID being 12.
 
Now, my question.  I have power automate sending an email when a new item is created.  Sending details from the master list AND the details list.  I use the filter array as shown below.   The problem is that Power Automate adds in "Apply to each".  So every time I add an item, I get multiple emails not only from the newest master item and subsequent detail lines, 1 email for each detail line, but also it goes through the list in a loop sending me emails for every record where the MasterID = ID.  
 
How can I stop the loop and just have 1 email with master and detail items when an item is created?  I hope this makes sense.  Let me know if further details are needed.  Thank you in advance.
 
Categories:
I have the same question (0)
  • Expiscornovus Profile Picture
    33,195 Most Valuable Professional on at
    Hi @98-911,
     
    What are you using in the Send an Email (v2) action? Are you referring to any of the properties of the Filter Array outputs?

    If that is the case you might want to use an expression to just refer a property of a single item of that array (for example the first item).
     
    In that case you can use the below format for an expression.
    first(body('Filter_array'))['NameOfPropertyYouWantToRetrieve']
     
  • 98-911 Profile Picture
    43 on at
     
    Thank you for your response.  Below is what I have for the email.  Should I have something else for "Select an output from previous steps"?  In my email body are your recommending something like this, 
     
    first(body('Filter_array'))['Title']
     
    first(body('Filter_array'))['Quantity']
     
    Thanks again!
     
  • Expiscornovus Profile Picture
    33,195 Most Valuable Professional on at
    Hi @98-911,
     
    My suggestion was to remove the apply to each action and use the expression directly in the e-mail action.

    Below is an example of that approach, if that helps?
    Btw, I also converted the ID of the trigger to a string in the Filter Array action, because my MasterID field is also of type text.
    string(triggerOutputs()?['body/ID'])
     
     
  • 98-911 Profile Picture
    43 on at

    I used the expression directly in the email action and received the following error.  Any insight on this?  I do appreciate your help!!  Further down is a screenshot of my email setup.
     
     
     
  • 98-911 Profile Picture
    43 on at
     
    I changed some things around, gathering data as an HTML table to drop into the email.  Which works, but I am still getting ALL of the items where the MasterID in one list is equal to the ID number in the other list.  I feel I am so close.  But I only want the latest items.  In simple terms, a new item is added to the master list with ID 56 and 3 lines are added to the details list with the MasterID also 56.  The email should only send details of those 3 lines.  I do hope all of this makes sense and I greatly appreciate the help.  Below is my flow in its entirety and what comes through via email.
     
     
     
     
  • Verified answer
    Expiscornovus Profile Picture
    33,195 Most Valuable Professional on at
    Hi @98-911,
     
    Good to know you want to use all matching items. In my shared approach I was only using the first matching item.
     
    Yes, you are very close. In your new approach replace the value property by the Body of the Filter array in the Select action From field.
     



    Happy to help out 😁

    I share more #PowerAutomate and #SharePointOnline content on my Blog, Bluesky profile or Youtube Channel
  • 98-911 Profile Picture
    43 on at
     
    Thank you!!!  That was it!  I sincerely appreciate your time and assistance!!!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard