Insert dynamic values in Email Templates from Custom Entities

As a Microsoft Dynamics CRM developer some times you need to work with Email Templates. Basically email templates save time when creating multiple email messages. Email templates contain pre defined data of CRM records, so we don’t have to reenter the same information again. Specifying dynamic values from out of the box entities is pretty simple but there are some instances when we might want to add dynamic values from custom entities. To which we don’t have any straight forward approach in CRM as we cannot add custom entity in email template.

So here is the requirement:

Send an email upon successful creation of Patient record using email template.
Registration email should contain the following format and values from Patient Record.

Dear <Patient Name>,

Thank you for visiting our Hospital.
We would like to inform you that your registration is successful, Please find the details below

<Type : Single Line of Text>
Patient Name : <Name of the patient>
Patient ID : <Patient Business ID>

<Type : Lookup>
Hospital : <Hospital ID>
Doctor : <Patient ID>

<Type : Date Time>
Registration Date with Time: <Registration Date>
Date Of Birth with Time : <Date Of Birth>

<Type : Currency>
Treatment Cost : <Treatment Cost>

<Type : Decimal Number>
Consultation Fee : <Consultation Fee>

<Type : Floating Point Number>
Estimated Amount : <Estimated Amount>

<Type : Multi Line of Text>
Address : <Address >
Patient Details : <Patient Details>

<Type : Multi Select Option Set>
Symptoms : <Type : Option Set>

<Type : Option Set>
Gender : <Patient Gender>
Patient Status : <Patient Status>
Status : 

<Type : Two Option set>
Hospitalization Required : <Hospitalization Required>
Show Patient Details : <Show Patient Details>

Best Regards,
Hospital Management.

Step – 1:
First create an Email Template of type “Global” by following below navigation Settings < Templates and then clicking Email templates and Click on ” New” button then Select Template Type “Global”  and click on “OK”.

Global Email Template-1

Give a proper name like “Patient Registration Template” as shown below

Patient Registration Email Template

Step – 2:
The below table gives the syntax for inserting dynamic values from Custom entities

S.No Field Type Syntax Example
1 Single Line of Text {!EntityLogicalName:FieldLogicalName;} {!new_patient:new_patientname;} or {!new_patient:new_patientbusinessid;}
2 Lookup {!EntityLogicalName:FieldLogicalName/@name;} {!new_patient:new_hospitalid/@name;} or {!new_patient:new_doctorid/@name;}
3 Date {!EntityLogicalName:FieldLogicalName/@date;} {!new_patient:createdon/@date;} or {!new_patient:new_dateofbirth/@date;}
4 Time {!EntityLogicalName:FieldLogicalName/@time;} {!new_patient:createdon/@time;} or {!new_patient:new_dateofbirth/@time;}
5 Currency {!EntityLogicalName:FieldLogicalName;} {!new_patient:new_treatmentcost;}
6 Decimal Number {!EntityLogicalName:FieldLogicalName;} {!new_patient:new_consultationfee;}
7 Floating Number {!EntityLogicalName:FieldLogicalName;} {!new_patient:new_estimatedamount;}
8 Multiline of Text {!EntityLogicalName:FieldLogicalName;} {!new_patient:new_address;} or {!new_patient:new_patientdetails;}
9 Multi Select Option Set {!EntityLogicalName:FieldLogicalName/@name;} {!new_patient:new_symptoms/@name;}
10 Option Set {!EntityLogicalName:FieldLogicalName/@name;} {!new_patient:new_gender/@name;}
11 Two Options {!EntityLogicalName:FieldLogicalName/@name;} {!new_patient:new_hospitalizationrequired/@name;} or {!new_patient:new_showpatientdetails/@name;}

Step – 3: Open the email template and place the required details in email body like below


Save the email template and you will see the updated email template like shown below


Step -4 : Create a workflow on Patient entity with create event and select the send the email step, associate the email template created above as shown below


Click on Set Properties and to see the below window and provide details in From/To and select “Patient Registration Email Template” and click on save and close and finally Activate the workflow


Step – 5: Create a patient record with relevant details as shown below


Step – 6: Go to Advanced find and search for Email Messages and click on results, You will see list of Email messages created by the system and select the relevant one and open


Here you go, your Patient Registration Email contains all the details which you have mentioned on the email template…!!!


15 thoughts on “Insert dynamic values in Email Templates from Custom Entities

  1. Hi Ravindarreddy

    I trust you are well. Thank you for publishing this piece.

    I have created an email template and made it available in a workflow and it works perfectly fine. the users are getting the email. i have however tried to edit and update the email template by adding some extra dynamic content to it. I saved and closed.

    The users gets the mail but however it is not the updated version of the email template. they still see the old content.

    May you please assist.

    Thank you


  2. Hello! We have problem. I want set unsubscribe link bu I can`t find where I can take receiver information and subject. We use this in campaign activity


  3. Hi – thanks for this – very useful.

    I was experimenting with this in the new email template editor and it works just like you described.
    There does not seem to be an option to create a global template in the new editor, but if you select the User one it seems to work fine if you send the email from an event in a custom entity. I was able to include fields from this custom entity in my email.

    Have you ever experimented with this to see if you can pull values from fields in a related entity? I suspect it is possible, given that you can do it in the native workflow email editor.



  4. HI, the on save the for lookups doesn´t seem to work for me either. Do you know if there was a change in the recent version ?


  5. there are many posts on how to insert dynamic text. What I need is a post that helps when the dynamic text does not get resolved into the actual field value. in the email the dynamic text shows like {!entityname:entityfieldname;}

    Anyone out there with any help at all would be appreciated. thanks DJ


  6. Hi, interesting read, but what I want to do is the opposite: values of a standard entity (contact) to be available in an e-mailtemplate sent from a custom entity (file). The values being first and last name. The template can be found when sending a mail from the contact page, but not from the file page.


  7. Hi, It worked perfect form me Thank you,
    but I want some fields from related entity so How to pull fields from look up entity?


  8. Thank for creating this!

    What about populating a url field? is it same as {!EntityLogicalName:FieldLogicalName;} ? i tried that but didnt work for me

    Also what about populating quick view data into an email template?


  9. Hi there, thank you for your post. It’s been helpful for me today, but I had a question:

    How can you link in relating tables to a table? What is the syntax for that?

    I.e I want to get the Telephone number of the Business Manager name sitting on the Contact table that is related to the Account table.


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 )

Twitter picture

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.