Set Email Signature using Workflow in Dynamics CRM 2016 Update 1

By | August 3, 2016

Introduction:

Email signature is an integral part of every email that we exchange. It adds a professional touch to our Emails. Microsoft Dynamics CRM 2016 Update 1 introduced Email Signature as an out of the box entity.  So that user can save time and be consistent in response. Previously, to add signatures in their emails user needed to perform some customizations. With the release of Dynamics CRM 2016, now user can insert signature in email using OOB functionality. You may refer this blog in order to know how to insert signature to emails in Dynamics CRM using OOB functionality. Email Signature using Workflow

However,when you create an Email using “Send Email” step in the OOB Workflow there is no option of “Insert Signature”.

Below is the snippet of the code to do it programmatically using C# code:

For this we need to create workflow Assembly which will give Email Signature as an Output Parameter.

//Creating Output parameter
[Output("EmailSignature")]
public OutArgument<string> EmailSignature { get; set; }

Here we have used the hardcoded email signature record id from CRM.

You can get email signature record id as shown belowEmail Signature using Workflow

Then we will retrieve the Email Signature record which we want to use.

Entity emailSignature =_service.Retrieve(“emailsignature”, new Guid(“AA8DD4EE-6D58-E611-80F4-C4346BDC5EB1”), newColumnSet(“presentationxml”));

The Email Signature record contains “PresentationXml” field which stores XML data for the body of the email signature.

Read the “presentation XML” from result and retrieve inner text of “emailsignature/presentationxml” node which contains the email signature.

XmlDocument doc = new XmlDocument();
string emailSignatureValue= string.Empty;
//Check whether the field contains value
if (emailSignature.Attributes.Contains("presentationxml") && emailSignature["presentationxml"] != null)
{
   doc.LoadXml(Convert.ToString(emailSignature["presentationxml"]));
  emailSignatureValue  = doc.SelectSingleNode("emailsignature/presentationxml").InnerText;
}
if (!string.IsNullOrEmpty(emailSignatureValue))
{
  EmailSignature.Set(executionContext, emailSignatureValue);
}

Use this value to set the Signature in email body by appending it after the desired content as shown in below screenshot.

Signature in email body signature using workflow

Conclusion:

Using this method, you can set an Email Signature using Workflow in Microsoft Dynamics CRM 2016 Update 1.

Before you move on to the next post, Check out what’s there in Maplytics August Release!