Dynamics CRM and the Internet of Things - part 3

This is the third post in a five-part series on how I integrated a Raspberry Pi with Microsoft Dynamics CRM to recognize contacts using automobile license plates. Although the code samples are focused on license plate recognition, the solution architecture I used is applicable to any Dynamics CRM + Internet of Things (IoT) integration. In my previous post, I showed how I set up my Raspberry Pi to capture images and parse them for license plate numbers. In today's post, I will show how to trigger the license plate recognition process and then use the extracted license plate number to find a contact in my Dynamics CRM organization with a custom workflow activity.

The approach

As I described in part 1 of this series, this approach uses a web resource, a dialog or some other interactive mechanism to call a custom workflow activity that instructs the Raspberry Pi to take a picture and return the parsed license plate number. The code hosted in CRM then searches for a contact with the returned license plate number and displays its details to the user. This requires that the CRM server be able to communicate with the Raspberry Pi, which may be challenging for CRM Online deployments.

Today I'll show how to call the custom workflow activity from a web resource, which will require the use of a custom CRM action so that the web resource can execute the functionality with a JavaScript call.

The custom workflow assembly

Interacting with the Node.js web page just requires making a GET request and then parsing the JSON response, so the approach to working with JSON data in custom workflow assemblies that I've used in several other posts will work great for this.

There are only a few changes required to that sample:

  1. Modify the JSON response classes to match the JSON object returned by the Node.js application.
  2. Modify the web request to be a GET instead of a POST.
  3. Add logic to search for contacts by license plate number and return the contact id as a string.
  4. Update the input/output parameters to return the contact, license plate and image details.

The code for the custom workflow assembly is available in my Crm-Sample-Code repository on GitHub here

One thing to keep in mind is that because I wanted to register the assembly in isolation, I had to create a hosts entry for my Raspberry Pi on my CRM application server since sandboxed assemblies cannot make web requests to IP address URLs. Alternatively I could have created an entry on my LAN DNS server.

The custom CRM action

A custom CRM action is used to wrap the workflow assembly so that it can be called from a web resource via JavaScript. The action simply passes a request to the workflow assembly and returns its response to the client.

The web resource

Finally a web resource is used so the user can interactively trigger the license plate recognition and open the contact record if a match is found. The web resource also displays the image that is captured by the Raspberry Pi so the user can validate that the license plate number extracted by OpenALPR matches the actual license plate number.

The web resource (lpa_checkplate.htm) is included in my sample CRM solution along with the custom action, compiled plugin and contact entity configured to store the license plate number. The sample CRM solution is available in my GitHub repository here.

Demo

Here's the web resource open a new tab.

Here's the result after I click the "check plate" button. The contact name is a hyperlink that will open the contact record in a new window.

That's it for today. In my next post, I'll show how to execute the license plate recognition and contact search with JavaScript directly in the web resource.