cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RolloV
Frequent Visitor

Loop and append to string list of email addresses

My goal is to send an email to a list of recipients. Data is gathered from an Excel table, with the list of recipients in column 1 (org) and 2 (individuals). The data needs to be filtered to each unique email address in column 1 (org). The people in column 2 are going to be added to the email in the To/CC. But I only want to add the filtered names, not the entire column. These should also be unique because each row will likely have the same information for individuals tied to the org.

 

I've created a flow that is working, with the exception of adding the people from column 2. I see my problem (step #5.2 below), but am unsure how to resolve it. I thought I could access my array of objects and then append nth item in the array to my string variable, but that seems wrong. I saw someone doing a Select and Join, but I'm not sure how to accomplish that. Looking for help on this aspect of my flow to add only people from column 2 that have been filtered by column 1 (org). 

 

Flow:

  1. List rows in Excel file
  2. Initialize String variable
  3. Select Org column
  4. Find unique org values
    1. union(body('SelectOrgCol'),body('SelectOrgCol'))
  5. Apply to each org
    1. Filter the array to current item
    2. Append to String variable (automatically wrapped in For Each) -This will fail as it pulls in the email addresses for all rows, not just the filtered ones.
    3. Create unique list of email in String variable
      1. union(split(variables('Email'),';'),split(variables('Email'),';'))
    4. Join unique list of emails in String variable with semicolon delimiter
      1. join(outputs('Compose_Unique'),';')
    5. Create HTML table
    6. Add table border
    7. Get metadata for file to attach
    8. Get file content
    9. Send email

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi , @RolloV 

Thanks for your response ! This is my sample flow's end result:

vyueyunmsft_0-1718247751523.png

This is my flow:

vyueyunmsft_1-1718247763517.png

 

And this is the expression in my Compose action.


union(
union(json(string('[]')),
xpath( xml(json(concat('{"root":{"item":',outputs('List_rows_present_in_a_table')?['body/value'],'}}'))) , concat( '/root/item[org_notification_email="',items('Apply_to_each'),'"]/auxiliary_email[ normalize-space(text()) != " " ]/text()'))) ,
createArray(items('Apply_to_each')))

 

If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance! 

 

Best Regards,

Yueyun Zhang

 

 

 

View solution in original post

12 REPLIES 12
v-yueyun-msft
Community Support
Community Support

Hi , @RolloV 

This is my test Excel , My column Name is [Org] and [individuals].

vyueyunmsft_0-1717469817698.png

And this is my test flow end result:

vyueyunmsft_1-1717469891699.png

 

vyueyunmsft_2-1717469956824.png

 

item()?['Org']


union(body('Select'),body('Select'))

 

union(json(string('[]')),xpath( xml(json(concat('{"root":{"item":',outputs('List_rows_present_in_a_table')?['body/value'],'}}'))) , concat( '/root/item[Org="',items('Apply_to_each'),'"]/individuals/text()')))

 

You need to replace the red font color to your column Name  in your side.

 

If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance! 

 

Best Regards,

Yueyun Zhang

 

Hi Yueyun, I am working on trying out your solution. So far no luck. I also misstated my initial request. I am not filtering unique org's, but org email addresses. There's two columns of email addresses, the first with the team DL, the second column has each individual user email. 

 

When I tried the first step I found the following errors when saving. In both cases I am entering in the text manually as an Expression as seen in the first picture:

  1. Switching to old designer: Enter a valid json: item()?['org_notification_email']

 

Old designer - invalid json.png

 

  1. Using the new designer: Enter a valid json: item()?['org_notification_email']

New designer - invalid json.png=

I can add more snapshots if needed. 

Hi , @RolloV 

You just need to put one here, and i recommend you to use the classic mode in flow.

vyueyunmsft_0-1717555758096.png

 

Best Regards,

Yueyun Zhang

Thank you. I noticed that as soon as I submitted this. 

The following is what I'm seeing now. 

Template validation failed.png

 

I renamed my fields as shown here:

union(json(string('[]')),xpath( xml(json(concat('{"root":{"item":',outputs('List_rows_present_in_a_table')?['body/value'],'}}'))) , concat( '/root/item[Org_id="',items('Apply_to_each'),'"]/auxiliary_email/text()')))

Hi , @RolloV 

As you rename your action name to "ApplyToEachOrg" ,  so you need to use this expression:


union(json(string('[]')),xpath( xml(json(concat('{"root":{"item":',outputs('List_rows_present_in_a_table')?['body/value'],'}}'))) , concat( '/root/item[Org_id="',items('ApplyToEachOrg'),'"]/auxiliary_email/text()')))

 

If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance! 

 

Best Regards,

Yueyun Zhang

 

 

That was it, thanks Yueyun. 

For some reason trying to set things up your way is not working. The Select appears to work, but not the Apply to Each. It's just an empty array coming in and therefore no output. Pics below.

union(body('SelectOrgEmail'),body('SelectOrgEmail'))

Select Org Email - output.png

union(json(string('[]')),xpath( xml(json(concat('{"root":{"item":',outputs('List_rows_present_in_a_table')?['body/value'],'}}'))) , concat( '/root/item[Org_id="',items('ApplyToEachOrg'),'"]/auxiliary_email/text()')))

Apply to each - output.png

The inputs and outputs only show [].

 

Even if this was working, how do I convert that to string/email format to add in the To or CC line of my email?

Thanks

Hi, @RolloV 

Thanks for your response
Do your Column name is [Org_id] in your side? Can you show me your column name in your Excel table or the output of your “List rows present in a table” action in your flow run history

union(json(string('[]')),xpath( xml(json(concat('{"root":{"item":',outputs('List_rows_present_in_a_table')?['body/value'],'}}'))) , concat( '/root/item[Org="',items('Apply_to_each'),'"]/individuals/text()')))

You need to replace the correct column in the red font color text.

 

If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance! 

 

Best Regards,

Yueyun Zhang

 

Hi, 

I think I had a typo somewhere that I didn't see before. It looks like it's working as the output is showing the two entries from the table below. 

 

Code: 

union(json(string('[]')),xpath( xml(json(concat('{"root":{"item":',outputs('List_rows_present_in_a_table')?['body/value'],'}}'))) , concat( '/root/item[org_notification_email="',items('ApplyToEachOrg'),'"]/auxiliary_email/text()')))

 

Output-Compose-01.png

 

 

org_id

org_notification_email

ws_name

Status

auxiliary_email

A-Org

Test@123.com

module_testing

Owner Pending

Aux@123.com

A-Org

Test@123.com

azure-TECH

Incomplete

Aux@123.com

B-Org

Test@123.com

gcp-test

Incomplete

 

C-Org

Test@456.com

azure-Prod

Incomplete

RolloV@test.com

 

What I'm not sure about now is how to put it all together. My goal is to address emails to the recipients in column "org_notification_email" and "auxiliary_email". The original flow worked fine to send to "org_notification_email". I'm not sure how I include this solution to add to my flow. 

 

The final results should be:

Email 1: Test@123.com; Aux@123.com

Email 2: Test@456.com; RolloV@test.com 

 

Here's my original flow design.

Automate Summary 01.pngAutomate Summary 02.png

Thanks

HI , @RolloV 

Thanks for your response! If you want to extract the emails in two columns, you can use this expression in your side.

union(
union(json(string('[]')),
xpath( xml(json(concat('{"root":{"item":',outputs('List_rows_present_in_a_table')?['body/value'],'}}'))) , concat( '/root/item[org_id="',items('Apply_to_each'),'"]/org_notification_email/text()'))),
union(json(string('[]')),
xpath( xml(json(concat('{"root":{"item":',outputs('List_rows_present_in_a_table')?['body/value'],'}}'))) , concat( '/root/item[org_id="',items('Apply_to_each'),'"]/auxiliary_email[ normalize-space(text()) != " "  ]/text()'))))

 

vyueyunmsft_0-1718161421822.png

 

The result is as follows:

vyueyunmsft_1-1718161528955.png

 

If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance! 

 

Best Regards,

Yueyun Zhang

 

 

 

Hi Yueyun, 

My apologies the initial post stated in error that I was filtering on Org_ID. That was incorrect and I was trying to explain that above. Please just ignore the Org_ID column completely. It's not relevant. 

I need to filter my table by the org_notification_email. This controls the list of associated resources, and who I will need to send emails to. In addition, I have individual users who I need to add to the the email and they are listed in the auxiliary_email column.

 

The core of my flow is shown here. 

  1. Select org_notification_email column
  2. Compose - Find unique org values
    1. union(body('Select'),body('Select'))
  3. For each
    1. I filter by the current item
    2. Create the HTML table to list the associated rows
    3. Send email with attachment

Original-logic.png

 

Thanks

Hi , @RolloV 

Thanks for your response ! This is my sample flow's end result:

vyueyunmsft_0-1718247751523.png

This is my flow:

vyueyunmsft_1-1718247763517.png

 

And this is the expression in my Compose action.


union(
union(json(string('[]')),
xpath( xml(json(concat('{"root":{"item":',outputs('List_rows_present_in_a_table')?['body/value'],'}}'))) , concat( '/root/item[org_notification_email="',items('Apply_to_each'),'"]/auxiliary_email[ normalize-space(text()) != " " ]/text()'))) ,
createArray(items('Apply_to_each')))

 

If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance! 

 

Best Regards,

Yueyun Zhang

 

 

 

Hi Yueyun, this worked for me and I was able to apply it to the email with a little change to convert to string. Thanks for the help here. 

Now I need to figure out how to update the exact record in the spreadsheet based on that filter I used. 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (2,090)