A common steps to use in a Dynamics CRM workflow is Send email. This is pretty straightforward: in this single step you can define the sender, recipient(s), body and all other available fields of the email entity. The sent email will also be visible in the Timeline of the regarding record.
When I set out to replace the Dynamics CRM workflow with a Flow, my goal was to use an email template to send an email using dynamically generated activity parties. Also, the email had to be visible in the Timeline of the regarding record. Quickly it became apparent that this is less straightforward in Flow than I hoped for.
In short, the following steps have to be taken:
- Initialize objects for the recipient(s), sender and email.
- Initialize an array for the activity parties.
- Set the recipient(s) and sender objects.
- Append the recipient(s) and sender objects to the activity parties array.
- Set the email object using the activity parties array.
- Use the unbound action SendEmailFromTemplate.
The example Flow I created for this post looks like this:
Let’s break down each step.
Initialize objects recipients, sender, email
The first thing to do is initialize empty objects for the recipient(s), sender and email. Note that these objects will be initialized empty because we will retrieve the values to set the objects later in the Flow.
Initialize array activityparties
Because of the nature of the activityparty entity, an array needs to be initialized to hold the activity parties. In the following steps, the sender and recipients objects will be appended to this array.
Set object sender and append to activityparties array
Now, let’s set the sender object and append it to the activityparties array by using the correct activity party type1.
One thing to keep in mind is that you might need to use decodeUriComponent('%40')
to display the @ symbol. The formula used to set the sender object is:
{
"participationtypemask": 1,
"partyid_systemuser@{decodeUriComponent('%40')}odata.bind": "/systemusers(UserID)"
}
Of course, replace UserId
with the primary key of the System User you retrieved in an earlier step.
Bonus tip: if you always use the same sender, you can set the sender object directly at initialization.
Set object recipients and append to activityparties array
The recipients object is set and appended in the same way as the sender object, but differs in participationtypemask.
Set object email
The sender and recipients objects are complete and appended to the activityparties array, time to set the email object!
The formula is:
{
"email_activity_parties": @{variables('activityparties')},
"@{decodeUriComponent('%40')}odata.type": "Microsoft.Dynamics.CRM.email
}
Perform unbound action SendEmailFromTemplate
Finally, the email object is ready and we can use the SendEmailFromTemplate unbound action to send our email.