3 May’17

Dynamics 365, EnterpriseCreate Attachment of Signature/ Pen control data in Dynamics CRM

Introduction

We already saw how to use Pen/ Signature control in Dynamics CRM in the previous blog: http://www.cloudfronts.com/adding-signature-control-mobile-tablets-dynamics-crm/

In this blog, we will see how to generate an image of the pen control data and store in Record as an attachment.

Steps

  • As we saw in the previous blog, the signature captured from phone is stored as a multi-line text field in Dynamics CRM record. And we cannot see the signature image in web browser.

Now it will be a common scenario where the Users will need to see the Signature image in browser as well. This is how data is captured on Web browser.

  • We need to write custom code which will:
    • Read this data
    • Convert the data to an image
    • Store the converted image as an attachment in the CRM record
  • For this I, have written a generic plugin which will do the above actions.
  • You can see the core plugin code with comments below. I have also added the plugin to Github for reference: Github Link
//// The plugin is registered on the Post Update on "Customer Approval" field on Opportunity.

Entity entity = (Entity)context.InputParameters["Target"];

  //// The field which stores the data for Signature

  string signatureFieldName = "new_customerapproval";

  if (entity.Contains(signatureFieldName))
  {
      string encodedData = entity.GetAttributeValue<string>(signatureFieldName);
                 
      //// Remove the additional Metadata from the text generated.
      int startIndex = encodedData.IndexOf("base64,") + 7;
      encodedData = encodedData.Substring(startIndex, encodedData.Length - startIndex);
      tracer.Trace(encodedData);

      string contentType = "image/png";
      Entity Annotation = new Entity("annotation");
      Annotation.Attributes["objectid"] = new EntityReference(entity.LogicalName, entity.Id);
      Annotation.Attributes["objecttypecode"] = entity.LogicalName;
      Annotation.Attributes["subject"] = "Customer Signature"; //// You can have any subject as required.
      Annotation.Attributes["documentbody"] = encodedData;
      Annotation.Attributes["mimetype"] = contentType;
      Annotation.Attributes["notetext"] = "Customer Signature Attached"; //// Again, add any note text as needed
      Annotation.Attributes["filename"] = "Customer Approval Signature.png"; //// OR Any name as required

      Guid annotation = service.Create(Annotation);
 }
  • This plugin should be registered on update of the Signature control field. In this case, it is “Customer Approval”. It is preferable to have the step run asynchronously.
  • We can now see the attachment on the record.

 

If you have any issues or need more information, please post in the comments section below.

Written by

Someswara Siripuram

CRM Team Leader

2 thoughts on “Create Attachment of Signature/ Pen control data in Dynamics CRM”

  1. Hey somesh, How can we merge this pencontol field into a document to send an email, it should display the signature inside a document, how can we do that.

    1. Hi Vishnu,

      Unfortunately there is no direct way to show the signature directly in the document. I am assuming you want to use this in Word templates.

      But the field does contain the image content information in Base64 sting which you can use in HTML field to regenerate the signature. You may then leverage this to add to your document. It will also depend on how you want to generate the document and send in email.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.

Want to streamline your business processes?

  • This field is for validation purposes and should be left unchanged.

Recent Articles

  • Design Views in App Designer – D365

    11 April’ 2018

    Introduction: Create and edit public or system views by using the app designer Description: Dynamics 365 sales app des...

    Read more
  • Call Management in D365 Field Service

    10 April’ 2018

    Introduction: This blog provides a solution to requirement of Client for Call Management in D365 Field Service. Scenari...

    Read more
  • Fetch Hierarchical data for Product Category in Dynamics 365 Operations

    10 April’ 2018

    Introduction: In this blog article, we will see how we can fetch hierarchical data using X++. How to fetch? We will ta...

    Read more
  • PowerBI April 2018 Update: Combo Chart Line Formatting

    10 April’ 2018

    Introduction: PowerBI introduced the feature to format line styles and legends for line charts a while ago. However, th...

    Read more
  • Power BI April 2018 Update: Q&A Explorer

    10 April’ 2018

    Introduction: In this blog we will explore some of the new features added to Power BI. Power BI has upgraded its Q&...

    Read more