In this blog, I will show you how to embed a DocumentsCorePack template into the body of an email in a Dynamics 365 workflow. Doing this allows you to create rich email content, giving you more control than traditional out of the box email editing tools.
For this example, I am using the Gift Certificate template that ships with DocumentsCorePack. It’s not the fanciest template, but you have full flexibility on layout and formatting as you would with a normal Word document.
I have created an on-demand workflow which I can run on Contacts. The workflow will simply send an email to each Contact, but obviously, in a real life scenario, you’d want to check if the Contact has an email address first.
The first step in the workflow is to create a document using the template. To do this, we use a Create Step and create an MSCRMADDONS.com – AutoMergeWorkingItems record as follows. TemplateToExecute is the template that we want to use, and we also need to pass in the PrimaryRecordUrl and select HTML for the SaveAs option.
Next, use the Create Step to create an Email activity. We only need to set the From, To, and Subject. Leave the body of the email blank.
After that, use a Wait Condition to ensure that the document creation is completed. Then use the Create Step to create an MSCRMADDONS.com – AutoMergeWorkingItems record to attach the document to the email. We simply choose the AttachToEmail action and then reference the email and document created earlier in the workflow.
Instead of linking the document to the email as an attachment, it will embed the document into the body of the email, since we selected HTML as the output format earlier.
Finally, to send the email, we create another MSCRMADDONS.com – AutoMergeWorkingItems record – this time using the SendEmail action. It is important to note that this needs to be a separate record so you can control when each AutoMerge step takes place.
After we activate the workflow and run it on one or many Contacts, we will see Email activities generated using the template we have specified.