Skip to main content
Kofax

Script Locator Example

3014458

Question / Problem: 

Attached is a sample project demonstrating two ways to use the Script Locator to achieve the same behavior. In the sample project below the objective is to return all amounts on the page great than $1000.

Sample Script Project (KTM 6.2.1.0)

Scenario 1:

  • Project has Format Locator "FL" and Script Locator "SL".
  • Format Locator FL returns all amounts on the page in USD format with a dot (Example: $123.45).
  • Script Locator SL will iterate through all alternatives extracted from FL and then copy over all alternatives that are over $1000.
  • Field1 is assigned to SL.

Scenario 2:

  • Project has Format Locator "FL2" and Script Locator "SL2".
  • Format Locator FL2 returns all amounts on the page in amount format with a dot (Same as FL).
  • Script Locator SL2 will iterate through all alternatives extracted from FL2. However, instead of desired alternatives over, instead SL2 will delete alternatives from FL2 under $1000.
  • Field2 is assigned to FL2. This is because unlike SL, SL2 does not return any value. It simply manipulates the values of FL2.

 

As a review here is what each locator returns:

  • Format Locator FL: Returns all values in amount format with a dot (Example: $123.45).
  • Script Locator SL: Returns all values in amount format greater than $1000.
  • Format Locator FL2: Returns all values in amount format greater than $1000.
  • Script Locator SL2: Does not return any values, but deletes values from FL2.

 

Also it is important to note that the Script Locator must be defined after the locator it is referencing. If SL is defined before FL, then it will fail. Below is the script from the project:

' Class script: Sample

Private Sub SL_LocateAlternatives(ByVal pXDoc As CASCADELib.CscXDocument, ByVal pLocator As CASCADELib.CscXDocField)
   Dim i As Integer
   Dim FL As CscXDocField
   Dim oAlt As CscXDocFieldAlternative

   Set FL = pXDoc.Locators.ItemByName("FL")

   'Loop through all alternatives from Format Locator FL
   For i = 0 To FL.Alternatives.Count-1

      'Return all amounts greater than $1000. Also copies over all coordinates & confidence from Format Locator alternatives
      If CDbl(FL.Alternatives.ItemByIndex(i).Text) > 1000 Then
         Set oAlt = pLocator.Alternatives.Create()
         oAlt.Text = FL.Alternatives(i).Text
         oAlt.Left = FL.Alternatives(i).Left
         oAlt.Top = FL.Alternatives(i).Top
         oAlt.Width = FL.Alternatives(i).Width
         oAlt.Height = FL.Alternatives(i).Height
         oAlt.PageIndex = FL.Alternatives(i).PageIndex
         oAlt.Confidence = FL.Alternatives(i).Confidence
      End If
   Next
End Sub

Private Sub SL2_LocateAlternatives(ByVal pXDoc As CASCADELib.CscXDocument, ByVal pLocator As CASCADELib.CscXDocField)
   Dim i As Integer
   Dim FL2 As CscXDocField

   Set FL2 = pXDoc.Locators.ItemByName("FL2")

   'Loop through all alternatives from Format Locator FL2
   'Must iterate backwards or else an out or range error will occur if at least one alternative is removed
   For i = FL2.Alternatives.Count-1 To 0 Step -1
      'Removes any alternatives from Format Locator FL2 that under $1000
      If CDbl(FL2.Alternatives.ItemByIndex(i).Text) < 1000 Then
         FL2.Alternatives.Remove(i)
      End If
   Next

   'Uncomment the snippet below to show all remaining alternatives for locator FL2.
   'This will return the same results as locator SL

   'For i = 0 To FL2.Alternatives.Count-1
   '   MsgBox(FL2.Alternatives(i).Text)
   'Next

End Sub

 

Applies to:  

Product Version
KTM 6.3
KTM 6.2

 

 

  • Was this article helpful?