Dynamics 365: Format for DateTime field in email templates
Sending emails through Dynamics 365 is an essential function for automating order processing, for CI-compliant answering of support cases and other communication processes. Values from the entities (invoice, support case, customer data, etc.) are automatically transferred to the email. Very often, number and date formats are used, which do not lead to the desired result in the stored form. e.g. date field even without time component is output in the format "06.03.2020 00:00".
There is an easy way to adapt the format without programming.
In Dynamics 365 haben wir für Rechnungen zwei benutzerdefinierte Felder vom Typ Datum eingefügt, die den Leistungszeitraum auf der Rechnung ausgeben:
Das Email Template für die Rechnung soll in der Betreff Zeile den Leistungszeitraum anzeigen. Im Template Editor wurden die Felder über den Menüpunkt „Insert“ und Auswahl der Entität eingefügt.
When the template is executed, the field with the time portion is output, which is irrelevant in this case and should be removed.
Back in the Template Editor of Dynamics, we copy the subject line with Ctrl+C and paste the line into an HTML editor. We use Microsoft Visual Studio for this, but it works with any editor that supports WYSIWIG and SourceCode representation.
In the "Source" view, we can analyze the HTML code of the subject line. The fields are inserted into Dynamics 365 via the HTML tag "data-value".
In the "data-value" tag, the output can be adapted to the requirements. In this case, we only want to output the date part and append the format command /@date.
Back in Design View, copy the subject line...
… and copy it into the email template in Dynamics. A message will be displayed that the formatting will be removed, simply confirm it and save the template again.
The template can now be easily used in workflows without the need for manual formatting rework.
In the same way, formatting can be done in the email body and with any fields.