cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
theBrianL
Helper I
Helper I

Send HTML table to Unique Email

Wanting to send HTML table from Excel document to multiple users.  I want each user, which are identified by email address column, to receive HTML table with only those rows that contain that individual's unique email address(one email per person).    I was able to loop through and get the unique email addresses, but now need to send email with HTML table.  I'm stuck on second Apply to Each-getting an error about  "Apply to each must be parent for each scope."    Need help with how to modify flow for error and complete flow to append table with rows for each person, and send to each user based on that user's email address.  Thanks! 

 

theBrianL_0-1618424671186.png

theBrianL_2-1618424938149.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User III
Super User III

@theBrianL as you have a number of questions, I thought it would be easier to just build the flow from scratch and show you how it works. Did a quick video response and stuck it on YouTube: https://youtu.be/bS4eV_9hK9o

Let me know how you get on.

View solution in original post

8 REPLIES 8
Paulie78
Super User III
Super User III

With respect, your flow has quite a bit of complexity that you do not need. I would suggest the following changes:

  • Remove the variables. You do not need them.
  • After the list rows present in a table action:
    • Add a select action.
    • Put the select action into text mode.
    • Add the email address column as the only value. This will produce a simple array of email addresses.
  • After the selection action, add a compose action that does a union on the output of the select. This will give you unique email addresses.
  • Go into your apply to each action. Use your new email address array as the basis for the apply/each.
  • Use the filter array as you have already done, but on the right side of the comparison, use simply item() - which will represent the current email address.

 

With those changes, you should be good to go.

Pstork1
Dual Super User III
Dual Super User III

I would recommend a different approach to this.

1) Sort the Excel Table by the email address column.

2) Create a variable to hold the last email address processed and initialize it with some value. 

3) Create an array variable to hold the values for the HTML table.

4) Use an Apply to each Loop to process the rows.  Check each row to see if it matches the last email variable.  If it does append the information in the record to the HTML table array.  If it doesn't then convert the array to an HTML table and send the email.  Then re-initialize the HTML table array with the current row and update the last email variable with the current row email.

5) When you are all done with the Apply to Each Loop you will have one last email to send. So convert the HTML Table array to an Html Table and send it to the last email address variable address.

 

This way there is only one loop and you only process the emails once.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Can you tell me syntax for Union?  Also not sure what to put in the field From of Select?  I put Email and got an error saying it needed to be an array. I got an error on the union, so just needing help with that part also.  Thank you!  

theBrianL_0-1618443513245.png

 

 

Paulie78
Super User III
Super User III

@theBrianL as you have a number of questions, I thought it would be easier to just build the flow from scratch and show you how it works. Did a quick video response and stuck it on YouTube: https://youtu.be/bS4eV_9hK9o

Let me know how you get on.

View solution in original post

Thank you for putting that together.  That was awesomely helpful! Haven't put mine together yet, but that looks exactly like what I needed.  Thanks again Paulie.  

Paulie,  Could you show how to add a personal salutation that comes from the firstName column in same excel file and the number of rows returned?  So in the email body  says something like Hi Bob, You have 7 items.  I tried following the same logic and keep getting stuck.  That was a great video BTW!  

Paulie78
Super User III
Super User III

Yes, number of different ways to do it. If you just want to modify the flow you have already created on the basis of the video that I made you. Then it is probably easiest to do the following:

  • Add a select action within the apply to each loop.
    • Use excel as the "from"
    • Put the First name and email address into the select
  • At this stage you will have an array containing the first name and email address of everyone in the excel sheet. Add a filter array action
    • Use the newly created selection action as the data source for the filter.
    • Filter it so that item()['email'] equals items('Apply_to_each')

Then in a compose step you can use first() expression to get the first record from the filter array and that will contain their first name, salutation etc.

I added like you instructed, but getting an error on the filter array.  item()['email'] equals items('Apply_to_each')

 

theBrianL_6-1618694134528.png

 

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (1,613)