cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pgawronski
New Member

If body contains x TO email address equal elseif...

Good Afternoon,

 

I am new to here and trying to build the flow which will allow me to forward received email to the person mentioned in the body of the email with email address specified for each name form as per below:

 

Email with text Luke comes to purchase@xyz.com now this email should be forwarded with the appendix of the body message to luke@xyz.com else if text Mike is discovered in this email instead of Luke then it should go to mike@xyz.com and so on.

 

 

if(equals(variables('Body_to_variable'),'Luke'),'luke@xyz.com',if(equals(variables('Body_to_variable'),'Mike'),'mike@xyz.com'))

 

 

and I am adding this a expression to the TO field on Send an email V2 field and it does not work.

 

this is as per below:

pgawronski_0-1638877709794.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi again!
The approach you have chosen is to nest if() operators. 
So if you have one if() operator, you need two email addresses (one when evaluation is true, one when it's false)
But if you nest two if() operators, you will need three email addresses.
If you nest 20 if() operators, you will need 21 email addresses.
Not 100% sure Power Automate editor will allow to nest up to 20 if() expressions. Assuming it allows you to do it, and taking into account the expression will be sooo long and the chances to forget a comma or forget to close a parenthesis high, another option is to initialize a variable of type string (let's call it myTargetEmail) leaving it empty, next add a 'Switch' action block to evaluate if body equals Luke, Mike etc. and update variable accordingly. As far as I remember 'Switch' accepts up to 25 different values

efialttes_0-1638892575241.png

 


Both approaches have pros and cons
Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

4 REPLIES 4
efialttes
Super User
Super User

Hi!
Assuming you can receive an incoming email does not have an email body equal to neither Mike nor Luke, and that in such a case you plan to send it to error@xyz.com, I would try with the following expression:

 

if(equals(variables('Body_to_variable'),'Luke'),'luke@xyz.com',if(equals(variables('Body_to_variable'),'Mike'),'mike@xyz.com','error@xyz.com'))

 

Please also note equals() operator different from contains() operator:
By using equals() you expect email body exactly matching patters like 'Mike', 'Luke', else the email will be sent to error@xyz.com
By using contains() you expect email body containing patterns like 'Mike', 'Luke', else the email will be sent to error@xyz.com
hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Thank you for your message @efialttes, its kind a working as per your suggestion with: 

if(contains(variables('Body_to_variable'),'Luke'),'luke@xyz.com',if(contains(variables('Body_to_variable'),'Mike'),'mike@xyz.com','error@xyz.com'))

But only if 2 address are checked. Is this limitation? I would need about 20 to be checked is this possible?

Hi again!
The approach you have chosen is to nest if() operators. 
So if you have one if() operator, you need two email addresses (one when evaluation is true, one when it's false)
But if you nest two if() operators, you will need three email addresses.
If you nest 20 if() operators, you will need 21 email addresses.
Not 100% sure Power Automate editor will allow to nest up to 20 if() expressions. Assuming it allows you to do it, and taking into account the expression will be sooo long and the chances to forget a comma or forget to close a parenthesis high, another option is to initialize a variable of type string (let's call it myTargetEmail) leaving it empty, next add a 'Switch' action block to evaluate if body equals Luke, Mike etc. and update variable accordingly. As far as I remember 'Switch' accepts up to 25 different values

efialttes_0-1638892575241.png

 


Both approaches have pros and cons
Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

pgawronski
New Member

Thats great, I am currently testing the expression. I can see that your approach is much easier and more visually friendly. Thank you for assitance

Helpful resources

Announcements
Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Users online (1,312)