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

Set conditional Dynamic Content in 'Send an email' module

Hi Power Automate,

Have setup as follows: SharePoint List with a form for users to fill up --> Power Automate that auto-sends an email at specified time.

Am currently setting up the 'Send an email' module in Power Automate.

Like to prepare the email such that different categories are grouped and default value is "None".

Could an "If" condition with Dynamic Content be done in the 'Send an email' module?

Along the lines of "If, then, else": If([Movement]="Medical Leave",[Name of Person],"Null")

 

Email should look like:

Medical Leave

Person A

Person B

 

Fieldwork

None

 

Thanks in advance for helping.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Set conditional Dynamic Content in 'Send an email' module

@Sportynick one way you do this is shown below.

After your trigger, initialize string variables for each type of reason. Then get the items from your SharePoint list:
0-trigger-initVariables.png

Add a switch on the reason  and add a case for each for each reason (fieldwork, Medical Leave etc). It will get wrapped in an apply to each.

In each case add an append to string variable and add the relevant column from the dynamic content followed by <br> 

1-switch-case.png

Outside of the apply to each add the send an email action and make sure you select the </> icon so you add in the line breaks and it takes account of the line break in the step above.

2-sendEmail.png

 The result is as follows:

3-emailResult.png

 

Rob
Los Gallardos
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

View solution in original post

2 REPLIES 2
Sportynick
Frequent Visitor

Re: Set conditional Dynamic Content in 'Send an email' module

As a follow on to the previous email, script currently does not work as it should.

Instead of displaying one email with desired format (e.g. Medical Leave - Person 1, Fieldwork - Person 2), if I have two records in SharePoint list, two emails are sent out showing: 

1st Email:

Medical Leave

Person 1

Fieldwork

Person 1

 

2nd Email:

Medical Leave

Person 2

Fieldwork

Person 2

 

Extract of current script:

A. <u>Medical Leave</u><br>
<% if (@{items('Apply_to_each')?['Movement/Value']} = "Medical Leave") %>
<% { %>
<tr valign="top">
<td align="right">@{items('Apply_to_each')?['Person/DisplayName']}</td>
</tr>
<% } %>
<br>
<br>

Super User
Super User

Re: Set conditional Dynamic Content in 'Send an email' module

@Sportynick one way you do this is shown below.

After your trigger, initialize string variables for each type of reason. Then get the items from your SharePoint list:
0-trigger-initVariables.png

Add a switch on the reason  and add a case for each for each reason (fieldwork, Medical Leave etc). It will get wrapped in an apply to each.

In each case add an append to string variable and add the relevant column from the dynamic content followed by <br> 

1-switch-case.png

Outside of the apply to each add the send an email action and make sure you select the </> icon so you add in the line breaks and it takes account of the line break in the step above.

2-sendEmail.png

 The result is as follows:

3-emailResult.png

 

Rob
Los Gallardos
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

View solution in original post

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Users online (7,776)