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.

Adding Signature control on Mobile and Tablets in Dynamics CRM

Introduction

With CRM 2016, Dynamics added controls which can be used in Phones, tablets and some on web forms as well. One such important control is the signature control in Dynamics CRM.

This control is available for Phones and tablets, and very important in the modern sales process.

In this blog, we will see how to add Signature control on Mobile and Tablet forms.

 

Steps

  1. Create a Multi-line text field with minimum length greater than or equal to 15000. Let’s say the name of the field is “Customer Approval”

BlogImage1

  1. Add the Customer Approval field to CRM form.
    BlogImage2
  2. Add the Pen Control on the Customer Approval field.

BlogImage5

  1. Once you publish, you can now see this control on your Mobile and Tablet application. It will look like below. Note: You also need to select the check box below the signature for the app to save the data.

BlogImage3

Once Customer/ Person signs using the above, the information is stored back in CRM.

 

Other Information:

  1. The control cannot be used on Web forms. It will look like a Text box field. So, it is advisable to have this field locked or hidden on Web.
  2. On web form, and in CRM DB, the data is stored as the base64 format inside the field. So if you open the form on CRM, it will look like below.

BlogImage4

Conclusion:

  • Using controls for forms on mobile, and tablets vastly improves the user interface on handheld devices. It is important to understand controls and apply them at relevant places on CRM forms.

PS: I will be writing another blog, which will automatically convert the base64 data of the signature and store it as an attachment on the entity.