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

@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

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
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Users online (71,161)