Friday, January 17, 2020

How to make Email signature not editable in email body in Dynamic CRM


Recently, one of the clients asked me to have a preview of email signature on email entity (not to be edited) and signature must be a part of email body when sending out email from Dynamic CRM.

Solution

As the email body is an open editor user can edit the content within it, which might include email signature. The only solution which I find is to create a web-resource to show the preview of email signature and inject it into email body.

1) Let’s begin with creating a sample email signature in Dynamic CRM.
    Navigate to Settings -> Templates -> Email Signatures -> New



2) Create a Webpage (HTML) webresource



Here is a content of web-resource
Note : You can optimize the code further, here it is written to make it more readable.

<html>
<head>
<title></title>
<script>
    function resourceOnLoad()
    {
        debugger;
        var ownerId = parent.Xrm.Page.context.getUserId();
        var entityName = "emailsignature";
        var filterQuery = "?$filter=_ownerid_value eq " + ownerId + " and isdefault eq true";
        window.parent.Xrm.WebApi.online.retrieveMultipleRecords(emailsignature, filterQuery, 1).then(
            function success(result)
            {
                var signatureStr = result.entities[0].presentationxml;
                signatureStr = window.decodeURI(signatureStr);

                signatureStr = signatureStr.replace(/</g, '<');
                signatureStr = signatureStr.replace(/>/g, '>');
                signatureStr = signatureStr.replace(/&/g, '&');
                signatureStr = signatureStr.replace(/"/g, '\'');   // Single Quote

                xmlDoc = (new DOMParser()).parseFromString(signatureStr, "text/html");
                signatureStr = xmlDoc.getElementsByTagName('presentationxml')[0].innerHTML;

                document.getElementById('sig').innerHTML = str;
            },
            function (error)
            {
                Xrm.Utility.alertDialog(error.message);
            }
            );
    }
</script>
</head>
<body onload="resourceOnLoad()">
    <div id="sig">

    </div>
</body>
</html>


3) Inject the web-resource on email entity

Customize the form and Add Web Resource



4) Create a New Email Record and see email signature in preview.




Additional Findings

  • Set email signature as Default to automatically inject email signature to email body.
  • You cannot create any relationship with Email Signature entity in D365 CRM

Here are some more articles

>> Enhanced Email Communication in Dynamic 365 CRM

>> Configure email synchronization and Mailboxes on Microsoft Dynamics CRM 365 Online

>> How to make Email signature NOT editable in email body in Dynamic CRM

>> Send an email from Dynamic CRM in C#

>> Change the email template content dynamically in Dynamic CRM

>> Error: The email must have at least one recipient before it can be sent.

No comments: