Search code examples
kofax

access indexfields, batchfields and batch variables in custom module


In my setup form I configure some settings for my custom module. The settings are stored in the custom storage of the batch class. Given the variable IBatchClass batchClass I can access the data by executing

string data = batchClass.get_CustomStorageString("myKey");

and set the data by executing

batchClass.set_CustomStorageString("myKey", "myValue");

When the custom module gets executed I want to access this data from the storage. The value I get returned is the key for the batchfield collection or indexfield collection or batch variables collection. When creating Kofax Export Connector scripts I would have access to the ReleaseSetupData object holding these collections.

Is it possible to access these fields during runtime?

    private string GetFieldValue(string fieldName)
    {
        string fieldValue = string.Empty;

        try
        {
            IIndexFields indexFields = null; // access them
            fieldValue = indexFields[fieldName].ToString();
        }
        catch (Exception e)
        {
        }

        try
        {
            IBatchFields batchFields = null; // access them
            fieldValue = batchFields[fieldName].ToString();
        }
        catch (Exception e)
        {
        }

        try
        {
            dynamic batchVariables = null; // access them
            fieldValue = batchVariables[fieldName].ToString();
        }
        catch (Exception e)
        {
        }

        return fieldValue;
    }

The format contains a string like

"{@Charge}; {Current Date} {Current Time}; Scan Operator: {Scan Operator's User ID}; Page: x/y"

and each field wrapped by {...} represents a field from one of these 3 collections.


Solution

  • Kofax exposes a batch as an XML, and DBLite is basically a wrapper for said XML. The structure is explained in AcBatch.htm and AcDocs.htm (to be found under the CaptureSV directory). Here's the basic idea (just documents are shown):

    • AscentCaptureRuntime
      • Batch
        • Documents
          • Document

    For a standard server installation, the file would be located here: \\servername\CaptureSV\AcBatch.htm. A single document has child elements itself such as index fields, and multiple properties such as Confidence, FormTypeName, and PDFGenerationFileName.

    Here's how to extract the elements from the active batch (your IBatch instance) as well as accessing all batch fields:

    var runtime = activeBatch.ExtractRuntimeACDataElement(0);
    var batch = runtime.FindChildElementByName("Batch");
    foreach (IACDataElement item in batch.FindChildElementByName("BatchFields").FindChildElementsByName("BatchField"))
    {        
    }
    

    The same is true for index fields. However, as those reside on document level, you would need to drill down to the Documents element first, and then retrieve all Document children. The following example accesses all index fields as well, storing them in a dictionary named IndexFields:

    var documents = batch.FindChildElementByName("Documents").FindChildElementsByName("Document");
    var indexFields = DocumendocumentstData.FindChildElementByName("IndexFields").FindChildElementsByName("IndexField");
    
    foreach (IACDataElement indexField in indexFields)
    {
        IndexFields.Add(indexField["Name"], indexField["Value"]);
    }
    

    With regard to Batch Variables such as {Scan Operator's User ID}, I am not sure. Worst case scenario is to assign them as default values to index or batch fields.