Select Page

Table is a powerful compound element to capture two-dimensional data structured.  When writing rules for a Table element, ABBYY FlexiCapture 9.0 or 10.0 will have two different major behaviors depending on where the actual Script rule is placed.  Currently Table object provides access to Columns collection only, and not Rows collection.  This means that Table.Items returns the number of Columns.  In order to access Rows in a Table, a single columns needs to be selected so that me.Field(“Column1”).Items could be used to return Rows collection.  Note that the Column is called by the column name.

Here are the two different behaviors of the .Items depending on the placement of the script rule:

  1. The Script rule is stored in the Table or Column object (to which most developers are used to).  In this case the Column object has NO .Items collection.  Columns can be accessed individually by name as a regular field, but script acts on all cells at once.  The advantage of this script is simplicity since row iteration becomes unnecessary.  The disadvantage is that the Cells count is unknown, and we cannot work with individual cells.
  2. The Script rule is stored elsewhere, but NOT in the Table of Column object.  In this case the Column object has .Items or .Items.Item(i) which returns a collection of Cells.  We can iterate through each cell or access individual cells.

The above is targeting working with Columns and collections of Cells within columns.  So in order to process Rows, we need to access an appropriate .Items.Item(i) of each Column where (i) represented the actual Row number.  Also, we must use approach # 2, which is to store our Script rule outside of Table or Column elements.  The most logical place to store such scripts is right in the Document Section page element (called “Page” in your Definition).

For example, let’s use some imaginary Table with multiple rows and columns and generate some rules.

a)      If Charges cell is populated and any other cells are empty in a row, then require Verification on those other fields

b)      If Charges cell is empty, then skip Verification on other fields.  (I even suggest to improve this logic by maybe clearing other fields from misc. data if Charges cell is empty)

Here is the VBScript code:

'======================================
' This Rule checks certain conditions in each row of GridLines
'======================================
dim i

'check that columns exist
'large all-inclusive IF-THEN with AND operator
if me.Field("FromDOS").IsMatched and _
    me.Field("ToTOS").IsMatched and _
    me.Field("POS").IsMatched and _
    me.Field("Units").IsMatched and _
    me.Field("CPT").IsMatched and _
    me.Field("DC").IsMatched and _
    me.Field("Charges").IsMatched Then

    'iterate through all rows, the below action within For loop happens per row
    For i = 0 to me.Field("Charges").Items.Count-1
        'check if CHARGES cell has at least one character
        'and other cellsFROM, TO, POS, CPT, DC, UNITS are empty
        If Len(me.Field("Charges").Items.Item(i).Text) > 0 and _
        Len(me.Field("FromDOS").Items.Item(i).Text) = 0 and _
        Len(me.Field("ToTOS").Items.Item(i).Text) = 0 and _
        Len(me.Field("POS").Items.Item(i).Text) = 0 and _
        Len(me.Field("CPT").Items.Item(i).Text) = 0 and _
        Len(me.Field("DC").Items.Item(i).Text) = 0 and _
        Len(me.Field("Units").Items.Item(i).Text) = 0 Then
            'make all fields as NeedVerification
            me.Field("FromDOS").Items.Item(i).NeedVerification = true
            me.Field("ToTOS").Items.Item(i).NeedVerification = true
            me.Field("POS").Items.Item(i).NeedVerification = true
            me.Field("CPT").Items.Item(i).NeedVerification = true
            me.Field("DC").Items.Item(i).NeedVerification = true
            me.Field("Units").Items.Item(i).NeedVerification = true
        End If

        'check if CHARGES has no characters
        'and irrelevant if other cells FROM, TO, POS, CPT, DC, UNITS contain data
        If Len(me.Field("Charges").Items.Item(i).Text) = 0 Then
            'make all fields as NOT NeedVerification
            '(Perhaps a better option here is to clear out all other fields)
            me.Field("FromDOS").Items.Item(i).NeedVerification = false
            me.Field("ToTOS").Items.Item(i).NeedVerification = false
            me.Field("POS").Items.Item(i).NeedVerification = false
            me.Field("CPT").Items.Item(i).NeedVerification = false
            me.Field("DC").Items.Item(i).NeedVerification = false
            me.Field("Units").Items.Item(i).NeedVerification = false
        End If

    Next

End If

This code can be modified to perform any other logic while iterating through any number of Rows and calling on specific Columns by name to perform some actions.

Facebook Comments