Integrating ABBYY FlexiCapture and M-Files

Randy Sussner
Oct 26, 2021 6:30:58 AM

Integrate ABBYY FlexiCapture and M-Files

ABBYY’s FlexiCapture software is an excellent tool to ingest content providing capabilities such as OCR, capturing data from the page based on any number of rules, and a robust verification process where the end user can review the results for accuracy in OCR as well as field capture.

What FlexiCapture is not is a content management system. Enter M-Files. M-Files is a full featured content management system, including the ability to manage both document and non-document data. Essentially, if it is a data object, M-Files can manage it.

There is a logical step here to integrate these two systems. There are several use cases where documents enter an organization in many forms, both electronic and printed. Converting these to searchable, gleaning various bits of information from the page itself, and organizing this in an easy-to-use interface is directly in the wheelhouse of an ABBYY FlexiCapture to M-Files scenario. Listed below are several potential use cases for this architecture

  • Invoice automation
  • Insurance claims processing
  • Contract review
  • Purchase request
  • Conversion of legacy project data to a reportable format

Let’s take a closer look at the invoice automation scenario, as this is one of the most popular uses to FlexiCapture. In this scenario, FlexiCapture can read the invoice and capture all information, including

  • Invoice number and date
  • Purchase order matching
  • Line-item capture

In this scenario, there are several potential objects created. This depends on the design of the M-Files repository, but a typical scenario would have the following objects defined

  • Invoice
  • Invoice line item
  • Invoice document

You can see from the listing above that when a new invoice enters FlexiCapture and runs through its recognition processing. Many data objects can be exported to M-Files for storage. How is this accomplished? A custom export script!

 

A custom export script is added to the document definition in FlexiCapture. FlexiCapture supports several export types, including the document, the data captured, etc. A custom script allows the developer to utilize FlexiCapture’s built in libraries to access all the data and perform any task needed. Several languages are supported, including VBScript, Jscript, and C# among others. For this example, we are using C#.

Import required namespaces

using Abbyy.Connectors.Dms.ComFacade;

using Abbyy.Infrastructure.Logging;

using System.Collections.Generic;

 

Create the Factory instance that produces connectors for different document management systems

Factory factory = new Factory();

 

Set callback for logging – log messages from Connector will appear in FlexiCapture Processing Task notes. This makes for easy real-time debugging

factory.Init(Processing);

 

Create the connector object and add settings to be able to connect to the target M-Files vault

IConnectorSettings connectorSettings = new ConnectorSettings();

connectorSettings.DmsConnectionSettings.Server = "M-Files URL";

connectorSettings.DmsConnectionSettings.Credentials.Username = @"username";

connectorSettings.DmsConnectionSettings.Credentials.Password = "password";

connectorSettings.DmsConnectionSettings.Repository = "M-Files vault name";

 

Set the M-Files Object Type – this is the object type for the data coming into M-Files

connectorSettings.DmsDocumentDestination.FolderPath = "Invoice";

 

Set the Name or Title property in M-Files. Note that in the following scenario, we are setting the invoice number as the main name property. This is accomplished by retrieving the captured invoice number from the Document.Field(“field name”) code below

connectorSettings.DmsDocumentDestination.FileName = Document.Field("Invoice Layout\\InvoiceNumber").Value.ToString();

 

Set M-Files Class name

connectorSettings.MappedFields.DmsMetadataTemplate.Name = "Invoice";

 

Map the fields from captured FlexiCapture data elements to M-Files properties. The first value is a full path to the field in FlexiCapture. The second is the name of the M-Files property definition

Dictionary<string, string> pairs = new Dictionary<string, string>()

{

   { @"Invoice Layout\Misc", "Misc" },

   { @"Invoice Layout\Freight", "Freight" },

   { @"Invoice Layout\SalesTax", "Tax" },

   { @"Invoice Layout\Subtotal", "Subtotal" },

   { @"Invoice Layout\Currency", "Currency Type" },

   { @"Invoice Layout\Vendor\VendorId", "Vendor" },

   { @"Invoice Layout\InvoiceNumber", "Invoice Number" },

   { @"Invoice Layout\InvoiceDate", "Invoice Date" },

   { @"Invoice Layout\Total", "Amount" },

   { @"Invoice Layout\Status", "Invoice Status" },

   { @"Invoice Layout\Reason", "Status Reason" },

   { @"Invoice Layout\LineItems\TotalPriceNetto", @"LineItem\Total price netto" },

   { @"Invoice Layout\LineItems\LineItemName", @"LineItem\Name or title" },

   { @"Invoice Layout\LineItems\Description", @"LineItem\Description" },

   { @"Invoice Layout\LineItems\Quantity", @"LineItem\Quantity" },

   { @"Invoice Layout\LineItems\UnitPrice", @"LineItem\Unit Price" },

   { @"Invoice Layout\LineItems\Hours", @"LineItem\Hours" },

   { @"Invoice Layout\LineItems\DeliveryDate", @"LineItem\Date" },

};

 

Note the syntax, where the line-item data is automatically added as its own object in M-Files. What is happening here is the line-item object in M-Files is created and automatically associated to the Invoice object – all in one line!

{ @"Invoice Layout\LineItems\LineItemName", @"LineItem\Name or title" }

 

Set the mapped data pairs to the connector object

connectorSettings.MappedFields.FieldPairs = new MappedFields(pairs).FieldPairs;

 

Send all the data to M-Files

using (IAfcDmsConnector connector = factory.CreateConnector(DmsConnectorType.MFiles))

{

   connector.Init(connectorSettings);

   connector.Export(Document, exportImageSavingOptions);

}

 

You’ll note that we did not explicitly send the file, i.e., the OCRed PDF of the invoice to M-Files in this script. Through experience, it has been observed that it is best to add a second script for the document export. This is needed to set the proper M-Files object, class, and properties. Overall, it is the same process as above, with the following code added just before sending the package to M-Files. The following code specifies to send a searchable PDF to M-Files

 

IExportImageSavingOptions exportImageSavingOptions = FCTools.NewImageSavingOptions();

exportImageSavingOptions.AddProperFileExt = true;

exportImageSavingOptions.Format = "pdf-s";

exportImageSavingOptions.PdfTextSearchArea = TPdfTextSearchAreaType.PTSAT_AllPages;

 

That’s all there is to it. If C# is not your preferred language, you can use any of the other supported options. It is easy to see the power of this integration and how it can be applied to any number of use cases to export the captured data from a FlexiCapture instance to the proper target, including M-Files.

 

 

No Comments Yet

Let us know what you think