Customer Service Workspace – Macro to open an email based on template

Recently a customer of mine needed to have an agent script in their customer service workspace that opens an email using a template. I will explain how I achieved this in this blog post.

Hopefully you know we can have agent scripts in the customer service workspace within Dynamics 365. And also I hope you know we can call a macro from an agent script. As in this post I will focus on the steps in my macro!

My agent script step is shown below. You can see that it simply calls a macro called “Open Email Template”.

My macro is simple. But it did end up including a step I wasn’t initially aware I needed. As this is a two-step process. Firstly, I open an email from a template and then I trigger a second action that will set the “to” and “regarding” fields on the email.

My macro is below. You can see that my first action is “Open an email form with predefined template” and then my second action is an “Autofill form fields” action.

Open an email form with predefined template

My open email action is shown below.

The details of each parameter are given below.

Template ID: This is the GUID of the email template I wanted to use. For this test I simply picked one of the out of the box templates. The value you will use will no doubt be different to mine!

Entity record ID: Templates are often linked to a particular entity. In my example I have a case session. Meaning the anchor tab (first tab) in my session is a case record and I want to use my case as the input for the template. So I entered ${Session.AnchorTab.entityId}

Email recipients: I have populated something into this field, as it is mandatory. But as the next action will override the “to” field the value I have used it irrelevant. Hence I populated a “random” email address.

Entity logical name: I have already entered the ID of the record I want to use to generate this email. But here I need to state which table type it is. So in my example “incident”.

Below you can see the email template I selected for my test. I opened this in the advanced settings area of Dynamics 365. Notice that I grabbed the ID from the URL of the template. My email template will include dynamic values like case number that will be populated automatically when the template is opened.

Autofill form fields

Next, I have my “unexpected” action. This is used to set the “to” and “regarding” field on my newly opened email. As I want to send this email to the customer on the case and make it regarding the case.

I have shown my autofill action below. Notice that the entity logical name is “email” and I that set the “to” and “regardingobjectid” attributes.

My “to” attribute is set to ….


I admit this looks a little complicated! But looking closer we can see that the id, type and name attributes for my “to” field are being defined.

The id is {anchor._customerid_value} this is the ID of the customer from my case. (Typically, in my example a contact record but it could also be an account record.)

The type can be contact or account. {anchor._customerid_value@Microsoft.Dynamics.CRM.lookuplogicalname}
returns the table type associated with the customer in the anchor tab.

Finally, I return the name of the customer. For that I use … {anchor._customerid_value@OData.Community.Display.V1.FormattedValue}

My “regardingonjectid” field follows a similar pattern. But this time obtaining the id, name and type fields from the anchor tab is slightly easier!

[{“id”: “{anchor.incidentid}”,”name”: “{anchor.title}”,”entitytype”: “incident”}]

Completed Macro!

Below you can see that when an agent uses this macro an email opened in a new tab. The email contains the template I required and also is populated with information from my case. Additionally the “to” field has been set to the customer from the case.

Additionally scrolling down the screen shows me that the newly created email has also automatically been linked to my case.

If you want to automate creating emails from templates in the customer service workspace, I hope this blog post has been useful. Enjoy!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s