cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ppl
Post Patron
Post Patron

Use array values in Send email action

Hello.

I have an array with email values.

I need to put them into To field in send email action.

Number of items in array can be different.

ppl_0-1625221966711.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @ppl 

 

Slightly easier to explain in video format. Please see link below:

https://youtu.be/hWkzOnaFIxc

 

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

View solution in original post

11 REPLIES 11
annajhaveri
Super User
Super User

@ppl  if you have array as below 

annajhaveri_0-1625233304707.png

Then you  can use join expression as below in To field of Send Email action 

join(variables('EmailArray'),';')
annajhaveri_1-1625233349627.png

 

 

 

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.
Paulie78
Super User
Super User

Like this:

Paulie78_0-1625233486660.png

The expression in the emails compose action is:

join(xpath(xml(json(concat('{ "root": {"emails": ', outputs('Compose'), '}}'))), '//emails//text()'), ';')

Output is:

1@test.com;2@test.com;3@test.com;4@test.com;5@test.com

Ready for use in your To: field.

 

 

ppl
Post Patron
Post Patron

@Paulie78 @annajhaveri 

Thank you, but I need to put different groups of array to different send email actions

Sorry - I missed that. Change the expression to be like this for the first group:

join(xpath(xml(json(concat('{ "root": {"emails": ', outputs('Compose'), '}}'))), '//emails[1]//text()'), ';')

And this for the second group (in a separate compose action):

join(xpath(xml(json(concat('{ "root": {"emails": ', outputs('Compose'), '}}'))), '//emails[2]//text()'), ';')

 

ekarim2020
Super User
Super User

Another option is to use JSON with flow expressions. Although this is a bit more complex to do, it makes the flow cleaner and easier to understand.  Flows can become long and difficult to read.

ekarim2020_7-1625314296665.png

 

Starting with the following JSON object:

 

{
    "subjectEmailHeader": "The Operations Team Weekly News Digest",
    "sendEmailTo": "user1@email.com, user2@email.com, user3@email.com",
    "fromSendAs": "OpsComms@email.com",
    "replyTo": "admin@email.com",
    "ccEmail": "user3@email.com, user4@email.com, user5@email.com"
}

 

Create the flow

ekarim2020_6-1625314094818.png

Use the Dynamic content to populate the email fields:

ekarim2020_8-1625314347263.png

You can learn more here: Power Automate flow variables - How to use them

 

Ellis

 

ppl
Post Patron
Post Patron

@Paulie78 @ekarim2020 

Thank you for your answers. 

But if I dont know how many items will be in the array?

It depends on how much people will register.

How to use your formulas to each element of the array?

 

It does not matter how many items are in the array, the expressions I gave you will join them together however many there are.

ppl
Post Patron
Post Patron

@Paulie78 

Look,

I dont know how many items will be in array when my flow will be triggered

It may be two groups of users

[
     {
          "User1": "john@microsoft.com",
          "User2": "bill@microsoft.com"
     },
     {
          "User1": "kate@microsoft.com",
          "User2": "bob@microsoft.com"
     },

]

then I need to send two emails, in one email john@microsoft.com; bill@microsoft.com as reciepients and second with kate@microsoft.com;bob@microsoft.com as a recipients.

It may be three

[
     {
          "User1": "john@microsoft.com",
          "User2": "bill@microsoft.com"
     },
     {
          "User1": "kate@microsoft.com",
          "User2": "bob@microsoft.com"
     },
     {
          "User1": "sarah@microsoft.com",
          "User2": "jack@microsoft.com"
     }
]

 then I need to send three emails, in one email john@microsoft.com; bill@microsoft.com as reciepients and second with kate@microsoft.com;bob@microsoft.com as a recipients. The third will be an email with sarah@microsoft.com;jack@microsoft.com as a recipients.

I dont know how to explain it to Power Automate🙂

May be to put a variable ine your function

join(xpath(xml(json(concat('{ "root": {"emails": ', outputs('Compose'), '}}'))), '//emails[VARIABLE]//text()'), ';') 

And apply send email action to each element of the array?

I will slightly modify the flow I did you (It basically does this already, but will try to make it clearer). But I cannot do it right now. 

Hi @ppl 

 

Slightly easier to explain in video format. Please see link below:

https://youtu.be/hWkzOnaFIxc

 

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

ppl
Post Patron
Post Patron

@Paulie78 

Thank you very much!! 

But  I have the last question

ppl_0-1626186368767.png

 

If I have the last element of the array without pair

[
     {
          "User1": "john@microsoft.com",
          "User2": "bill@microsoft.com"
     },
     {
          "User1": "kate@microsoft.com",
          "User2": "bob@microsoft.com"
     },
     {
          "User1": "sarah@microsoft.com",
     }
]

how can i add them to the last group?

 

outputs must be looks like:

1st group  john@microsoft.com;bill@microsoft.com

2nd group kate@microsoft.com;bob@microsoft.com;sarah@microsoft.com

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Users online (2,368)