I have worked with Microsoft Power Automate (formerly known as Microsoft Flow) for a while, and I continually try to find ways to simplify development. As there is not a lot of relevant information on the Internet on specific tasks I need to perform, I end up performing trial-and-error experiments in flow construction. During these times, I find what does not work, but more importantly, I find what does work, and I consider these little victories a reason to celebrate and share with others. This blog is a result of one of those discoveries.
Recently, I noticed that the Initialize variable action (string type) supports HTML formatting that can be used to send out Outlook emails. Why would we want to do that when using the Send an Email(V2) action supports HTML-formatted emails?
For me, I wanted to create only one Send an Email(Vs) action rather than two since the only difference between the two emails was the email body. The FROM, TO, Subject, and other information were all the same. This reason was good enough for me change how I developed the flow. There is less to modify if a change to the requirements surfaces, and I do not have to drill down as far into the flow to make any adjustments.
Another possible reason to use this knowledge is to create one email body for several different email actions. The email body is the same, but the TO could be different, depending on the entity fields, along with the Subject Line. Either way, the concept shared in this blog will help you to build a flow that will only have one email body to use wherever you want.
There are not a lot of moving parts to illustrate the development of multiple email bodies per one flow. Here are the necessary required components:
- Initialize variable action
- Basic understanding of HTML
- Condition action
- Send an Email(V2) action
Navigate to make.powerapps.com, select your desired environment, create or select a solution, and from within that solution, click + New and then select Flow.
The trigger can be whatever you need; in this blog, I tapped into the When a record is created, updated or deleted Common Data Service (current environment) trigger.
Initialize Variable Action
After the new flow window populates, select New Step, and then search for Initialize variable action.
Set the default Value to null by selecting the Value textbox, selecting Expression, search for null, select it from the list, and then click OK.
It will look like this:
Boolean, Integer, Float, String, Object, and Array are the available choices for Type. At first, I thought I could use Object, but it expects a JSON formatted string. This is fine and dandy but would not work for an HTML-formatted email.
Then I considered using the Create HTML table action, but this action is expecting a result set of data like a series of columns and rows in MS Excel, not conducive to the email body I desired.
The Condition action will be used to determine which email body to send. In my case, the decision on what email body to create was dependent on a combination of several different data points. If one set of conditions were met, send the one-year email message; otherwise, send the two-year message.
Select New Step and then search for Condition action:
To make things easier for the final condition, I used one Boolean variable, named One-Year OR Two-Year Email, and set it to either true or false above this step with the combination of data points mentioned earlier.
If the condition is met, the One-Year message variable is set; if not, the Two-Year message variable is set.
I will pause here to briefly discuss HTML. You do not need to know much, but it is important to write HTML correctly or it will display horribly in the email.
Using a P tag will provide space above and below the paragraph:
Inside the HTML itself, you may use dynamic variables wherever it seems appropriate. The most common are name, address, and the current date.
Dynamics 365 for Sales Contact Full name:
Dynamics 365 for Sales Contact Address:
Send an Email(V2) Action
The rest is straightforward. Select New Step and then search for Send an email (V2) action:
Set the required fields, and then click inside the Body, select Expression from the dialog on the side, and choose the email body variable.
Now, when the flow is triggered, a different email body will be sent, depending on the various conditions.
With just a few actions, you can create as many different email bodies as possible for one email action to consolidate your flow development.
Are You Receiving Our Newsletters?
Subscribe to receive our monthly newsletters with the latest updates all in one place! Get important product information, event recaps, blog articles, and more.Subscribe