48 thoughts on “Dynamic Values for Custom Entities in Email Templates”

  1. Hi Mike,

    I’m trying to get previous email history (client responses and CRM outbound emails) added dynamically to a template, so that case history is easily visible in the body of every email.

    I’d ideally like to make this a default template similar to a signature.

    Do you know if either of these things are possible?

    1. Hmmm, that’s a tricky one. I’m guessing you’re hoping to include something like all of the related case activities, especially the body of emails? If that’s the case I don’t think it is possible.

      I am curious if there’s some way you can get the responses and email history into a field, then obviously you could use that field. Though I think even a field of multiple lines of text would still have a limit that would be reached pretty fast.

      Unfortunately, I think this could only be done through custom code, maybe through creating a customer workflow assembly, and then querying all the activities, and getting the body of the emails, then replacing a string with all the information it finds.

      Might not be as bad as it sounds though.

      Let me know if you have any other questions,


  2. Hi Mike,
    I can't get the yellow tag after writing
    {!prefix_entitylogicalname:prefix_fieldlogicalname/@name;} for lookup field, {!prefix_entitylogicalname:prefix_fieldlogicalname;#} for single line text that has url value, got this in part 2 with # after semi colon. AFter reading through the comments, I know that it is case sensitive, so I have checked the case and also the logical name and field name but it still couldn't work. I'm not sure what I have done wrong. P.S. for all the logical name I wrote it in prefix_entityname_fieldname, not sure this causes the problem.

    1. Hi Junny,

      I think the issue might be what you put on your post script, namely for the logical name being prefix_entityname_fieldname

      In general, the logical name for the entity is prefix_entityname and the logical name for the field is prefix_fieldname

      If you’ve tried both of those and still can’t get it, perhaps you can comment with the field and entity logical names you’re using and I can see if they look right.

      Also of note, if the entity is a native out of the box CRM entity, they logical name on those can be strange, usually has no prefix. You would need to go into the customize the system area to find what it is, which I’d be happy to help with if needed.

      Thanks for reading and sorry for my belated response,


  3. Hi Mike,
    Thank you very much for your quick response. Yes, I did it exactly as what you say. After I save, none of the fields turn yellow. Here are the steps I did, 1. Get a Display Name for custom entity - New Entity; 2. Get a Display Name for a field - New Entity ID (Type: Lookup); 3. In Email Templates, click New, Select Global for Template Type, and add {!New Entity:New Entity ID/@name;} in email body or Subject; 4. Save the change. The added fields don't turn yellow. It looks so simple, but I don't know what I did wrong. Thanks!

    1. Some correction for step 2: Get a Display Name for a field – Other Entity ID (Type: Lookup), and add {!New Entity:Other Entity ID/@name;}. Thanks!

      1. Hey Johny,
        I think the issue is you’re using the display name and not the logical name. The logical name is usually all undercaps and for custom entities always begins with a prefix (that comes from the publisher of the solution you’re working in, or defaults to new_ if you’re using the default solution), something like new_entity and likewise for the field name, it should be the logical name, not the display name, and again will begin with the prefix followed by the field name, so something like new_entityid

        Let me know if this doesn't solve the problem. Thanks!

  4. Hi Mike,
    Thank you for the information. Currently I am working on an Email Template using a custom entity for Subject and Body on CRM 2016. I just followed your guidance and all of your comments by adding fields from the custom entity (such as {!:/@name;}) in a new email template. Unfortunately, none of them is working, the result on the email still show {!:/@name;}. Please advise.

    1. Hey Johny,

      From what I can tell it seems like you might be missing a few pieces. To get the values to populate first add the {!

      Then, after that add the logical name of the entity (here’s a helpful site to finding it https://social.technet.microsoft.com/wiki/contents/articles/9214.microsoft-dynamics-crm-2011-entity-logical-name-and-entity-schema-name.aspx just navigate to Customizations>Customize the System and open the entities tab, and find your custom entity, and click on it).

      After that add a colon, :

      Then you need to add the logical name of the field on that entity, which can be found similarly to where you found the entity logical name. If the field you selected is a lookup value, then add the /@name to get the name of the lookup.

      Finally end it with a ;}

      You should know when you’ve done it correctly when you hit save. When it saves the page will refresh and it should turn yellow, this indicates it’s found the custom entity and the field value on that entity. Let me know if that helps!


  5. Hi,

    I'm trying to insert fields in an Invoice email template to include project information. Under record type, it only allows fields to be selected from Users, Accounts, Contacts, and Invoices. I need to add fields from Projects. I used your article as a guideline and the field turned yellow, but when generating the email, the field came back blank.

    Ex: Address:{!Project:Project Address Line 1;} 

    And feedback on why I'm getting a blank return?

    1. Hi,
      I can only think of two issues:

      1. The regarding object is Invoice, and you’re attempting to get the information off of a related entity Project, which it doesn’t currently seem possible with this. The dynamic values can only come from the regarding object you have selected. In order to get the information for Project the Project record needs to be the regarding object.

      2. My other thought, I’m not totally sure if this is true, but it sounds like you may have made the Template type Invoice? Again, I cannot confirm this to be true right now, but I believe this makes the system think it’s only looking for field values on Invoice, and you’re trying to get them off of project. So I think the Template might need to be of record type Global in order to use Project

      And finally as I was typing I noticed one more thing, in your example, you pasted the following,
      Address:{!Project:Project Address Line 1;} 
      and I noticed the field you have, Project Address Line 1, is using the display name, but not the schema name. The schema name doesn’t have any spaces, and for custom entities (which I believe Project is) usually looks something like new_projectaddressline1, where new can be what ever prefix you selected.

      Hope that helps! Let me know if not, and thanks for reading!

      -Mike Watt

  6. Thanks for the lesson...

    I remember one of my clients asked me to do this and at that time, had no idea how... and now I see it was this easy.

    1. Hey Paul,
      I looked some and couldn't find any way of getting the values from a related entity. I could only get it to use values from the regarding field record. Please comment if you do find a way


  7. Hi Mike,

    I have a requirement where I have text line field say 'Code' contains numeric value like (123456789) and in email template I need to format the value of field as 12345-6789.

    Is it possible to format this fields dynamic value on template itself?


    1. Hi Harsh,
      Thanks for reading. As far as your request, I don't believe this is possible using the dynamic values. I couldn't find any way to format values that it retrieves.
      If you do find a way, please let me know, I'd be very interested.


  8. Denise McDonough

    Trouble getting to work with Dynamics 365. In a global template, if I copy & paste in dynamic fields from a custom template, it works. If I try to type in exactly the same dynamic fields, it doesn't put the yellow box on them and doesn't translate them in the template, eg.
     {!Contact:Account Name;} (shows with yellow highlight) and {!Contact:Account Name;} (typed in, no yellow highlight).

    I've tried this with many different entities and fields. I'm doing this to test it works before I move on to my real goal which is to pull in fields from a custom entity.
    Any suggestions?

    1. Hey Denise,
      Thanks for reading! Sorry for the late response. I believe the issue is that you're not using the correct schema name for the field. There are a few ways to find these technical names, one is by opening the form editor on the entity (usually located under the eclispes in the ribbon bar area of an entity), then double click the field you're looking for, in this case that would be the Account Name field on contact. From that pop up, go to the 'details' tab, and the name in the Name field is what you will use, so this would be parentcustomerid. Also the entity needs to be in it's technical name. I could tell you how to find that if you'd like as well, for Contact it's s easy as just all lower case, contact (custom entities are a little more tricky)
      So try typing the following
      I added the '/@name' because it's a lookup and this will give you the name of that account (ass opposed to a GUID)
      Hope that helps, again sorry for the slow response!

      1. oops I added an exclamation mark at the end of that, so try

  9. Wow...this is a real gem! I have worked with several clients that needed this and had no idea it existed. Where did you find documentation on this???

    1. That's the strangest part, I didn't. I had to kind of hunt through their code to find it all. I was and still am pretty shocked they don't have any documentation on this.

  10. Hi does this functionality work in Dynamics 365?I tried it, not working. My publisher name is different its not "new". Can you let me know is there any work around?

    1. Sorry mate its working perfectly on Dynamics 365. i have just tested again. Thanks for the blog really useful

  11. Hey Pooj,
    Sorry for the really slow response. I was trying to think of a work around but nothing comes to mind. Displaying dates has always been a sore spot for me with CRM. I do mention how to display just the date, but I believe it does it based on the Organization's base date format. Wish I had a better thought or idea for you. I'd love to hear if you thought of a work around for this.

    Thanks for reading,

  12. Hi Mike,

    Thank you for all the information, are really helpful. I have a question of how to format the date from MM/dd/yyyy to dd/MM/yyyy in an workflow email body.
    Value I get currently:
    Workflow body
    Date & time received: {Created On(Case)}
    Output Email body
    Date & time received: 2/9/2017 9:43 AM (this is 9th Feb 2017)

    This happens while the server as well as client date format already have formatted to be Australian Date Format which is dd/MM/yyyy h:mm tt.

    Thank you in advance,

  13. Hi Mike,

    I have a requirement to incremented value every time a new mail was sent out with that particular template for a case.

    Can this be done ? Let me know if you found out a way.

    Thanks for all the information 🙂

    1. Hi Pavan,
      Thanks for reading!
      Can't think of a super clean way to do this...
      We'd need to persist that incremented value somewhere.
      I'm not sure where though...perhaps we could add a field on the case? though the incremented number wouldn't be persistently consistent through all cases...

  14. Hi Mike, Hi Venkatesh,

    sorry for replying so late...
    Well I did find a solution but I was using a different workaround.
    The dataset is created via workflow. I just added another step to the workflow which updates the data with the URL. Therefore I added a field on the custom entity which then contains the URL of the Dataset.

    In the e-mail template I therefore can relate to the field with the URL. In combination with the href you can have a nice link to the dataset which shows the name but if you click on you get forwareded to the dataset.

    If you got further questions feel free to ask. I'll try to check this website from time to time again.

  15. Thanks for this great blog entry!

    While i was experimenting with above knowlege two questions came up to my mind.

    1. How can I retrieve the URL of the record? I want to include the URL in my E-Mail.
    2.In reference to Hamid's comment above: Could someone provide me the html5 code you're using to embed hyperlinks with comments? (I have very little knowlege of html5 but the idea you're describing sounds great)

    Any help is appreciated 🙂

    1. Hey Daniel,
      So, unlike with dialogs and workflows, where you can select Record URL (Dynamic) from the side menu, there's nothing really similar to that from here. However I did find a bit of a work around. all you really need to open a new record is the server name (just your crm url), entity name and entity id.
      So within an anchor tag, for the href you could do something like this.

      {Server Name}/main.aspx?id={Entity Id}&newWindow=true&etn={Entity Name}&pagetype=entityrecord

      So for the entity id, we can use a dynamic value, and since by default the lookup dynamic values populate with the id or GUID, we can use that.
      For Entity name we can just hard code that with the entity's logical name.
      So for example if we wanted the url to the contact record, the url would look similar to,{contact:contactid;}&newWindow=true&etn=contact&pagetype=entityrecord

      and as usual, when you save the template, the contact area should turn yellow if you did it correctly.
      Let me know if you have an further questions!

      1. Hi Daniel ,

        I have this requirement to show the record link in my email content.
        could you please let me know if Mike's solution worked for you.
        How you resolved it.


  16. Can you imbed dynamic fields straight into HTML Code then paste it in the email body. If so, what is the code that needs to be entered into the HTML code

    1. Hey Hamid,
      I believe what you're asking is if you can combine html with the dynamic values? I was able to, here's a simple hyperlink anchor tag that grabs the website url from the account and uses the account name as the text,
      Let me know if that answers your question

      1. well apparently you can embed hyperlinks into the comments
        so I tried to show, within an anchor tag, I set the href="{!account:websiteurl;}" and then in between the start of the anchor I added {!account:name;}
        This sets the link to the accounts url and the text as the account name

  17. Vitor,
    I tried it with the Campaign entity and it worked. The string I used was {!campaign:name;No Name Found}

  18. Hi,
    Thanks for the tip. It works fine but has issue with regarding: Creating Entity with an invalid parent. Entity: Email, ReferencingAttribute:regardingobjectid
    I'm wondering why crm sdk doesn't have this syntax. Do you know if we could find it documented some where?

    1. Hi Michael,
      I've looked far and wide for any sort of documentation on this and have found nothing from Microsoft.
      As far as your question, I'm not sure I'm answering it, but I believe the issue might be that when setting the dynamic values it's trying to insert the values based on the regarding object. Meaning it's trying to find the 'Regarding Object' from the entity it's regarding, which unless it's an email it probably won't have.
      Hopefully that makes sense, let me know if there are any other questions.

      1. Hi Mike,
        The issue was in the setting. Emails are not allowed for the custom entity. The workaround is to create a child workflow (Custom action) and send a proper entity there as a parameter and then query the related entities.
        Yeh, it's so pity about lack documentation from MS. Is there any other source?

    1. Hi Tal,
      This will technically work for a template of any type, but in order to create an email template that references custom entities it has to be of Template Type: Global.

        1. Jeff,
          I tried it with CRM 2016 and it worked fine. The field references are case sensitive so make sure that is correct. For example if I wanted to show the Account name it would be {!account:name;No name found}

          1. Hey Mike,

            Account is a supported entity for using email template on. I can do it as well, but for other entities such as Campaign, even following the structure that shows above, i am not able to get a yellow dynamic tag upon saving the record.

            Can you check and see if you can do it for Campaign?

          2. Hey Vitor,
            Thanks for reading, I was able to get it to become yellow, make sure you have the casing right, here are two examples I did that worked for me,
            The Campaign's Code {!campaign:codename;}
            The Campgin's Name {!campaign:name;}

Comments are closed.

Show Buttons
Hide Buttons