Create 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: https://someshblogs.wordpress.com/2017/05/03/adding-signature-control-on-mobile-and-tablets-in-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.

BlogImage4

 

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.

 

BlogImage6

 

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

Advertisements

One thought on “Create Attachment of Signature/ Pen control data in Dynamics CRM

  1. Hi,
    It’s really interesting for me, but, I don’t know how create a field that call this function. I have created the signature field correctly in my app but I need to change base64 to png register and save it in a new field. Please, it’s possible a complete manual for that?
    I’m really lost for creating JavaScript file and after use it.
    Many thanks for your help!.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s