How to Insert Dynamic Tables into Workflow Created Emails in Dynamics 365

Jordan Hohepa, 26 October 2017

Recently for a project I was a part of, one of the requirements given was to insert a table with dynamic values into an email in Dynamics 365. The email this table was being inserted into was being created within an existing workflow using the “Create Record” step for the ‘Email’ entity. The screenshot below shows an example workflow I created with the same email creation step inserted in a workflow created for Accounts and an extra step for adding the table.

image

To meet this requirement, I decided to use a Custom Workflow Activity (CWA) just after the email was created and just before sending it. In this example, I will use the same methods but I will not be sending out the final email from Dynamics 365.

This CWA would take both the newly created email and the record the workflow is running on, in this case account as inputs. The CWA would first retrieve the data to be shown in a table, which in this example was a list of Contacts related to the Account. Note that the “sdk” variable is of type IOrganizationService.

image

The  next step would be to format the retrieved values and place them nicely in a table. The code in the screenshot below shows how I created and populated the table but this step could be done in a number of different ways.

image

Then finally the CWA would find the placeholder within the emails description, which in this case was “<table>”, replace it with the created table and update the email.

image

The screenshot below shows the finished email sent out with the dynamically populated table values in Dynamics 365.

image