cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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

@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
Frequent Visitor

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>

@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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Users online (15,597)