Monday, September 26, 2016

Email template : Show Date or Time portion only for DateTime attribute

Sometime when sending emails using email templates we do not want to show time portion, e.g. BirthDate.

Contact record

Email Template


Email using template



 To remove time portion from BirthDate in email template, you need to modify template XML.
  1. Create Solution, with email template
  2. Export Solution to local machine
  3. Open Customization.xml file.
  4. Look for email template
  5. In Email template XML, check  presentationxml tag.

        It will look like

  <template><text><![CDATA[Dear&#160;]]></text><slugs><slug><entity>contact</entity><attribute>fullname</attribute></slug><default></default></slugs><text><![CDATA[ <font face="Tahoma, Verdana, Arial" size=2 style="display:inline;"></font><div>Your date of birth in system is&#160;]]></text><slugs><slug><entity>contact</entity>&lt;attribute>birthdate</attribute></slug><default></default></slugs><text><![CDATA[ </div><div><br></div>]]></text></template>


6. This is decoded HTML, you can use online HTML decoders to decode, or look for attribute, e.g. BirthDate

 < template >< text > <![CDATA[Dear ]] >< /text >< slugs >< slug >< entity >contact< /entity >fullname< /attribute >< /slug >< default >< /default>< /slugs >< text >< ![CDATA[?< font face="Tahoma, Verdana, Arial" size=2 style="display:inline;" >< /font >< div >Your date of birth in system is ]] >< /text >< slugs >< slug >< entity >contact< /entity >< attribute >birthdate < /attribute >< /slug >< default >< /default >< /slugs >< text >< ![CDATA[?< /div >< div >< br >< /div >]]>< /text >< /template >


7.Change  < attribute >birthdate < /attribute >  to  < attribute >birthdate/@date < /attribute >

8. Encode template HTML, and put it back into Customization.xml file in presentationxml tag. 

9.  Save customization file, Zip and re-import to CRM.

10. Don't Forgot to publish solution.

Note: It might be when you re-import solution some special character added in template.

Remove special character, save template





Now try now email with same template, and you will see only date portion of BirthDay.


In case want to show only time from datetime field, in email template then change 

7.Change  < attribute >birthdate < /attribute >  to  < attribute >birthdate/@time < /attribute >





11 comments:

  1. I honestly had no idea it stored/sent birthday info. Thanks for bringing it to my attention! I’ll have to fix this.

    Dynamics GP Ecommerce

    ReplyDelete
  2. This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you.
    Whmcs templates

    ReplyDelete
  3. Thanks for sharing. However, it doesn't work for me in CRM 8.2. I have tried /@ and /%40 and even %2f%40. Nothing works and always displaying the timestamp.

    ReplyDelete
  4. Great post! It is working fine for Dynamic CRM 2013. I have requirement to change Date format like YYYY-MM-DD to DD-MM-YYYY , How can we do that Mahadeo? - Bishnu

    ReplyDelete
  5. I'm using D365, and I want this to be selective ?

    ReplyDelete
  6. THANK YOU FOR THE INFORMATION
    PLEASE VISIT US
    CRM Solutions



    ReplyDelete
  7. Replies
    1. It works only you need to remove the special characters suffixed. Sometimes it is not special character, it just suffixes a blank space at trailing end, you need to just open the email template using CRM UI and place the cursor just after the date field and remove the empty (blank) space added at end. And save the email template it should work.

      Delete
  8. this is totally crazy. There should be a simpler way. Come on Microsoft. you can do better than this...

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Able to get only the Date part with this approach..but this is changing the timezone format in the email...the format coming in the email template is mm/dd/yyyy even though the crm timezone format was dd/mm/yyyy, any clue how to fix this?

    ReplyDelete