Search code examples
c#kofax

Kofax Export Connector - get value from IndexField


I created a mapping for my Kofax Export Connector. This connector interacts with an external application using webservices.

I want to connect the indexfield values to field IDs of the external application. Currently I have a dictionary containing the ID of the external application and the index field ID.

Dictionary<double, double?> // external fieldID <-> indexfieldID

The key is nullable because a field might not be assigned. Instead of passing the indexfieldID to the external application I want to pass in the value of this indexfield.

Currently I have this

releaseSetupData.CustomProperties.Add("MetaFieldID", "IndexFieldID");

and the desired result would be

releaseSetupData.CustomProperties.Add("MetaFieldID", "IndexFieldValue");

How do I get the value of the index field? The indexfield itself has no "value" property and the Kofax user is able to setup a custom field with a custom dataType. So how would a value look like?

I don't get it from the Kofax Capture Export Type Library API Reference Guide


Solution

  • Generally speaking, Kofax organizes any kind of mapped data as so-called Links. However, it does not take care of mapping anything on its own, that is our job (for some reason). You will find two different objects at your disposal:

    1. Your setup script will contain a reference to a ReleaseSetupData object, usually named SetupData.
    2. Your release script has another reference to a ReleaseData object, namely DocumentData.

    Now, all links established during setup time will become available during release time. Said links can contain different kinds of data, for example index fields, batch fields, Kofax values, or custom properties. Now, let's say you have the index field "FirstName" on your document class, and you do want to access its value during release time - here's what you need to do.

    Setup Script

    setupData.Links.Add(
            setupData.IndexFields["FirstName"].Name, 
            KfxLinkSourceType.KFX_REL_INDEXFIELD,
            setupData.IndexFields["FirstName"].Name);
    setupData.Apply();
    

    Please keep in mind that those links are similar to dictionary entries, so you can't link the same item twice. I usually like removing all links when my setup script loads, and add them again when it unloads again (and note that you can safely loop over the setupData.Indefields collection to add all fields instead of just a single one).

    Release (Run) Time

    During release, all links are then made available in the DocumentData.Values collection. To access your index field and its value, here's what you need to do. The following assumes you already set up a Dictionary<string, string> named IndexFields, and it further shows you how to access all other kinds of links (batch fields, custom properties, et cetera):

    foreach (Value v in DocumentData.Values)
    {
        switch (v.SourceType)
        {
            case KfxLinkSourceType.KFX_REL_BATCHFIELD:
                BatchFields.Add(v.SourceName, v.Value);
                break;
            case KfxLinkSourceType.KFX_REL_DOCUMENTID:
                break;
            case KfxLinkSourceType.KFX_REL_INDEXFIELD:
                // index fields may also contain table fields
                if (v.TableName == "")
                {
                    // this is a regular index field
                    IndexFields.Add(v.SourceName, v.Value); 
                }
                else
                {
                    // this is a table field! 
                }
                break;
            case KfxLinkSourceType.KFX_REL_TEXTCONSTANT:
                TextConstants.Add(v.SourceName, v.Value);
                break;
            case KfxLinkSourceType.KFX_REL_UNDEFINED_LINK:
                break;
            case KfxLinkSourceType.KFX_REL_VARIABLE:
                break;
        }
    }
    

    If you wanted to map Kofax Index Fields to some external ID, you could safely do so using Custom Properties. Example: you can assign the id 42 to FirstName during setup (just create a property grid with a custom class), add the Custom Property during setup time, and then access its value during release. That way you could maintain ids via the setup form without the need to ever rebuild your solution.