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

Add e-mail recipient by if statement

I have a send email action and want it to check an array (attachments to the email) for a specific word (in filename), and if that exists, add an email to CC.

 

I'm not sure how to write it, concat was the closest thing to a "add text"-function I could find.

Spoiler
if(contains('BrandlarmVCCAtt'), 'SATS'),concat('nicki.vike@sats.se')

Any ideas on how to get it to work? Ideally directly in the CC-field with extra variables and Compose-actions.

 

b1tz_0-1650990492655.png

 

3 REPLIES 3
joelzehring
Advocate III
Advocate III

I think you're on the right track. Just need to change the syntax a little.

 

if(contains(string(variables('attachmentArray')), 'BrandlarmVCCAtt'), 'name@test.com', '')

 

The if expression takes three arguments. In this situation, the first argument is the conditional presence of a substring inside a string is the condition. The second argument is what to return if the condition is true (an email string). The third argument is what to return if the condition is false (an empty string). Source: Reference guide for expression functions - Azure Logic Apps | Microsoft Docs

 

The contains expression takes two arguments. In this situation, the first argument is the string you want to search within, and the second argument is the substring you're search for. Source: Reference guide for expression functions - Azure Logic Apps | Microsoft Docs

 

I don't think you need to use the concat expression since the if expression is placed inline after a string.

Hmm.. But the syntax for contains is:

contains('<collection>', '<value>')

 And the name of the collection/array is 'BrandlarmVCCAtt' and the string to search for is 'SATS', so shouldn't it then be like: 

if(contains('BrandlarmVCCAtt', 'SATS'), 'nicki.vike@sats.se', '')
joelzehring
Advocate III
Advocate III

Thanks for that clarification... If "BrandlarmVCCAtt" is the name of a variable in your flow, then the syntax would be: 

if(contains(variables('BrandlarmVCCAtt'), 'SATS'), 'nicki.vike@sats.se', '')

 

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.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (3,979)