In this blog I would like to describe the real life systems which I had the honor to plan, develop or support. My aim is to warn my readers about mistakes in the architecture I saw and to enrich them with my real life experience. Also I will describe the internal processes which accompany the technical design of a complex system.

Monday, August 20, 2012

I have just finished Proof-of-Concept for one of our customers. The PoC was a demonstration of capabilities to automate paper document flow based on a custom solution for MS Dynamics CRM 2011. It involves barcodes generation, bulk document printing, scanning of paper documents and automatic recognition of the barcodes and handwritten text within the documents. The solution uses QR Codes to identify the documents.

The most interesting is that we can produce some real documents (see photos inside!) and automate process using standard office equipment like printer and fast speed scanner. That was a big part of work and it have been successfully delivered within three weeks. Lets see how I have done this.

Overall solution architecture

Lets consider a business process we would like to automate. This process is pretty common for large organisations like banks, insurance or logistics companies. All this organisations have to work with large amount of customers who potentially can be not honest. That is the reason why each bank will ask you about all your personal details and could even ask for certified copies of documents. As we can see in this PoC, the certified copies is to much.

The company provides logistics services for persons all over Australia. So, we have the customers and some of them live in a rural area. Our customers can have an internet connection or can not have. So, some of them may use a company web site to apply for contract. The others will use a paper forms to apply. No matter how customer will apply for contract, we should have the same business process for electronic and paper applications. This documents will contain personal information and that is the reason to store it in a secured storage if we have legal permission to do so.

After customer have applied, the personal information should be validated against 100 points identification. Based on the validation results the company employee will offer a personified contract conditions for the customer. Later, the customer can call or email company to change the personal information or contract conditions.

Technical solution for Dynamics CRM

As a basis for interaction with the customers we may choose Microsoft Dynamics CRM 2011. This system fits to the requirements of a wide interaction with the customers no matter which communication technology they will prefer. The system supports direct information storing via web service call. It it useful because we need to integrate it with the existing company web site. Additionally we can use a mechanism of e-mail queues which I have described in a previous post. This mechanism will be helpful for receiving a scanned documents. The last thing is a support for workflow processes which allows us to change status of an application after information verification.

On the other hand, usage of the product could have a potential limitations. For example in this PoC I have recognised documents using open source libraries with unsafe code. This means that the code must be executed with a full trust. But such scenario is not compatible with a sandbox isolation mode required for Dynamics CRM Online. So, this solution must only use an on-premises installation of the CRM.

The technical solution involves custom Silverlight controls for displaying barcodes and signatures. It is required because of standard functionality limitations in case you need to display a picture, a list of links or some rich contents. Also we need two custom plugins. The first will fill barcode information for newly created record. The second will recognise barcode and text from document on receiving of an e-mail in an e-mail queue.

QR Codes generation

The barcodes could encode some metadata. The metadata in the PoC are used for document type and identifier storing. If the company uses barcodes on all paper forms than it could be useful for routing scanned documents to right location and for recognition purposes.

The QR code itself is a text. White space is a space character. Black space is a pseudo graphic character. The only issue when we would like to print a barcode is a font for printing. The font should be monospace without line spacing and with fixed line height. It potentially could be a problem if we going to print a barcode on a employee computer and it have no proper font. That is why the font should be included in a printing template.

There are a lot of libraries available for code generation. I suggest C# port of ZXing because of simple API and barcode recognition functionality. So, on creating of a record in a system we could generate a metadata and encode it as a QR code using custom Dynamics CRM plug-in.

Bulk document printing

The records from Dynamics CRM than could be printed using a standard mail merge functionality. A responsible employee will choose documents, for example in status Draft and will initiate a new mail merge.

The mail merge mechanism allows us use not only letters printing, but also bulk e-mail sending. All we need in our solution is create a new organisation mail merge template, which can be used for all bulk printing tasks by different members of a postal team.

The set of the records will be directed to MS Word which provides simple step by step wizard for printing. The good thing about this solution is that we can change individual letters during print preparation.

The result is presented in WYSWYG form. All we need is send this document set on printer. In this sample I will print welcome letters and personalized application forms for three customers. On document printing we will receive an activity creation dialog which allows us to run a workflow activity in Dynamics CRM. So, we could automatically change status of all printed documents to Printed or Sended.

The member of a postal team will go to printer and will print the ream.

Print document journey

The printed document than can be folded and embedded in an envelop. In the PoC we had an envelop with transparent window. So, the address can be printed directly on top of the document. And no need to print an address on the envelops.

The post will deliver the document to a customer. The customer will fill, sign and post back the application form. The postal team will unpack all incoming messages and scan it using high speed printer.

Scanning to email

Almost all modern scanners or multifunctional devices can scan a document and send it to an e-mail. The company service desk team can help to set up a dedicated button on a device to scan the document to CRM’s message queue an e-mail in one click (sorry, tap).

Unfortunately, such customization is not always possible. For example HP’s equipment I worked with had no such capacity, but RICOH’s had.

All scanned document will be delivered to a Dynamics CRM message queue if it is configured properly. You can refer to me previous post about such configuration.

On receiving of a scanned document we can provide text recognition logic in form of a second Dynamics CRM plug-in.

Automated recognition of a scanned document

The task of a document automatic recognition is not so trivial. The most important part here is an implementation. We need to parse a multipage PDF document. Than to recognise pages with the barcodes, extract document type from metadata and apply document grid according to document type. The main idea behind the document grid is that we should know exactly where to find a separate letter square. Only for a separate letter we than could apply recognition algorithm which based on a simple neural network.

During the PoC I have found that ZXing is not recognising barcodes if document scanned in resolution less than 200 dpi. It is really depends on the size of a QR code. That is why I have attended a research of a proper barcode size and font. I must admit that for production implementation of a system I would choose a custom font instead the existing monospace fonts. The important issue with barcode recognition is that if PDF have been produced by virtual printer than the barcode is presented as a text not as picture. So, my plug-in have to recognise this. It have been done by custom algorithm.

When we have a type of the document it is time to apply a grid. We need to find a document corners, scale a grid and extract images of separate letters. The document corners have been marked with a black boxes of pseudo graphic characters. As a corner detection algorithm the SUSAN algorithm have been chosen. The implementation by AForge uses an unsafe C# code. That is why the proposed solution is not working in MS Dynamics CRM 2011 Online. It is required a full trust instead of CRM Online plug-in sandbox isolation.

The result and following workflow

We almost there. Text and signature is recognised. The security around signature can be set up using different forms for security roles.

Now we can run a workflow to verify the document and than automatically place the information in a standard Account entity which is a final storage.

The scanned document can be placed in a security storage. For example it could be done automatically for MS SharePoint. In PoC I have integrated the solution with Open Text Document Management system using web service call from the plug-in code.

Access from a web interface

For use case of an access from web interface I have demonstrated sample web application based on Silverlight. How to integrate it with Dynamics CRM 2011 using web services I also wrote in the previous post.

This is it! If you have some questions or you would like to see that solution in Dynamics Marketplace do not hesitate to contact me. Thank you for reading!