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

Get email adress from dynamic content / sharepoint list

I'm trying to dynamically get email adresses from a sharepoint to the "To" field in Send email action (positioned below showed apply for each).

 

Flow:

1. List files in OneDrive folder

2. Condition to check if any filenames contains keywords (DRIP and PVT in this case)

3. If yes - Get file content and append to array for attachment to Send Email, then move those files to a "Sent"-folder.

4. Send email with attachment

 

This works as intended.

 

But now I'm trying to dynamically get email adress instead of typing it out in the flow. I created a sharepoint list with several columns, two of them containing different keywords (field_ 3: DRIP, field_2: PVT).

 

field_1 contains the email adress.

 

Basically I want the flow to add email adress from sharepoint list matching the same keywords in the files handled in the loop.

 

If I have the Send Email action outside the loop I cant get the dynamic value from the "Get Items"-filter (which is inside the loop), and if I put the Send Email action INSIDE the loop I can choose the dynamic content from "Get Items" but then the Send Email action gets put into another "Apply for each" and the flow sends multiple emails if attached files are 2 or more.

 

If it's 3 files it sends 3 emails (email 1 with attachment 1, email 2 with att 1+2, email 3 with att 1+2+3).

 

Also dont really know the syntax for get items filter to give me the email adress if the keywords are matched.. 😞

 

test1.png

test2.png

8 REPLIES 8
v-jefferni
Community Support
Community Support

Hi @b1tz ,

 

The send email action should be inside the loop, the point is you will get an array from "Get items" from SharePoint list. So, the solution will be:

1. Set filter query expression to:

substringof('DRIP',field_ 3) and substringof('PVT',field_2)

contains is not supported in Odata filter query:

https://sharepains.com/2018/11/12/sharepoint-get-items-odata-filter-query/

 

2. Initialize a string variable, use join function to concatenate all the filtered emails with a ";" and use it for the send email To parameter:

join(outputs('Get_items')?['body/value']?['field_1'],';')

https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#j...

 

Hope this helps.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

But how do I stop the email from sending 20 times to the same adresses when it finds 20 files matching the filter? I had to put it outside the loop the prevent that.

v-jefferni
Community Support
Community Support

Hi @b1tz ,

 

I thought there would not be duplicate values from the filtered items. If there are, you could add a variable, use union function the get the distinct values before the join function:

join(union(outputs('Get_items')?['body/value']?['field_1']),';')

 

Hope this helps.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

b1tz_0-1648458464980.png

Got this error. Looks like it's because that column is "Multiple lines of text"? Can you only use "Single Line of text"? Makes no sense. 

Also: 

b1tz_1-1648459057054.png

It didn't output the email, only the same expression. So email recipient becomes "join(union(outputs...". Tried setting variable as array but didnt work either because "Set variable" writes in 'string'.

In case it helps, here is the whole flow incl. sharepoint list. 😞  

  

 

flow1.png

flow2.png

flow3.png

flow4.png

v-jefferni
Community Support
Community Support

Hi @b1tz ,

 

Answer to the first question, Multi-lines of text columns are not supported for filter query, below is a blog where introduces a workaround:

https://tomriha.com/power-automate-filter-on-multiple-lines-of-text-sharepoint-column/

 

For the second question, the result you need to set in To property of Send an Email action is exact a sting:

a@123.com;b@123.com;c@123.com;

 

Hope this helps.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

Yes, I thought your join function would get the email(s) to the variable "DRIP mail", then I choose the variable in send email "To" field but it didn't work.

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.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

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.

Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022- Season 2 has kicked off!

Users online (4,001)