Workflow Agent Sample
Article # 3031936 - Page views: 628
Issue
Workflow Agent samples in C# using Capture .NET libraries.
Solution
Below is a sample Workflow Agent that processes after the Recognition Server module which simply writes out the Index Field values of all the Documents in the Batch to a text file.
First add references to the following Kofax Capture API DLLs:
Kofax.Capture.ACWFLib.dll Kofax.Capture.SDK.Workflow.dll Kofax.Capture.SDK.Data.dll
Some COM-related aspects exist and are required such as
In the project properties, assembly Info, COM
Visible
must be set to True
.
The same class attributes, (i.e., Guid
, ClassInterface
, ProgId
), are required.
Following is the complete source code for the Workflow Agent.
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Threading.Tasks; using System.Runtime.InteropServices; using Kofax.Capture.ACWFLib; using Kofax.Capture.SDK.Workflow; using Kofax.Capture.SDK.Data; namespace WFAExportValues { [Guid("7F819B7B-7F21-4F5E-8699-51F09C93A088")] [ClassInterface(ClassInterfaceType.None)] [ProgId("WFAExportValues.ExportValues")] public class ExportValues : IACWorkflowAgent { public void ProcessWorkflow(ref IACWorkflowData oWorkflowData) { if (oWorkflowData.CurrentModule.ID.ToLower() == "fp.exe") { try { IACDataElement oRoot = oWorkflowData.ExtractRuntimeACDataElement(0); IACDataElement oBatch = oRoot.FindChildElementByName("Batch"); IACDataElement oDocument = oBatch.FindChildElementByName("Documents"); IACDataElementCollection oDocColl = oDocument.FindChildElementsByName("Document"); using (StreamWriter sw = new StreamWriter(@"C:\ProgramData\Kofax\CaptureSV\Logs\WFAIndexData.txt", true)) { foreach (IACDataElement oDoc in oDocColl) { IACDataElement oIndex = oDoc.FindChildElementByName("IndexFields"); IACDataElementCollection oIndexColl = oIndex.FindChildElementsByName("IndexField"); sw.WriteLine("Document: {0}", oDoc["UniqueID"].ToString()); foreach (IACDataElement oField in oIndexColl) { sw.WriteLine("Name: {0}, Value: {1}", oField["Name"].ToString(), oField["Value"].ToString()); } sw.WriteLine("----------------------------------------------------"); } } } catch (Exception ex) { using (StreamWriter sw = new StreamWriter(@"C:\ProgramData\Kofax\CaptureSV\Logs\WFAIndexData.txt", true)) { sw.WriteLine("************************************"); sw.WriteLine("Error: {0}", ex.Message); sw.WriteLine("************************************"); } } } } } }
Level of Complexity
High
Applies to
Product | Version | Build | Environment | Hardware |
---|---|---|---|---|
Kofax Capture | 11.x | N/A | N/A | N/A |
References
-
Article # 3031936