HTML source in Dynamics CRM emails

By | June 10, 2013

Dynamics CRM is, likely, not the best tool to do email templating, but, on the other hand, sometimes it’s just easier to send notification emails from Dynamics CRM using a combination of email router and CRM workflow.

The problem with this sort of quick and dirty approach is that there are limits to what CRM allows us to do.. Though, sometimes, there are workarounds which we can apply, so below is one of them.

Basically, I’ve run into a bit of  a problem trying to set HTML source for the emails sent from Dynamics CRM, and here is what happened:

  • Since we cannot update html source directly, I figured I would add a new plain text field (html source) to the email entity
  • And, then, I’ve added that field to the email form
  • The problem with this field was that I could not simply copy the contents of that field to the email description using workflow “set properties” option since CRM kept adding extra HTML body tag to the email description in that case
  • So, I ended up with a simple plugin which I attached to the email entity (create/update), and which only purpose is to copy the contents of my new html source field to the original email description field

Here is the source:

if (context.InputParameters.Contains(“Target”) &&
context.InputParameters[“Target”] is Entity)
{
Entity entity = (Entity)context.InputParameters[“Target”];
if (entity.LogicalName == “email” && entity.Contains(“new_descriptionhtml”))
{
if (entity[“new_descriptionhtml”] != null)
{
entity[“description”] = entity[“new_descriptionhtml”].ToString();
}
else{
entity[“description”] = null;
}

                    }
}

Leave a Reply

Your email address will not be published.