Kofax DOKuStar Validation User Manual
Page 13
DOKuStar Validation for Ascent Capture
Page
• 9
Before getting more into the details, here is a second way of solving the same problem:
Dim WithEvents ctrl As Controller
Private Sub Application_OnProjectLoaded(ByVal App As Application)
Set ctrl = App.Project.DataSet.Controller
End Sub
Private Function ctrl_OnFieldChanging(ByVal Controller As Controller, ByVal Field As Field, ByVal
SubField As Field, ByVal VerifyEventArgs As VerifyEventArgs) As Boolean
ctrl_OnFieldChanging = True 'Preset return value
If Field.Document.Name = "Invoice" And Field.Name = "Amount" Then
If Val(Field.Value) > 1000 Then
If MsgBox("You entered a value > 1000. Please Confirm.", vbOKCancel) = vbCancel Then
ctrl_OnFieldChanging = False 'User clicked cancel, so stay in the field
End If
End If
End If
End Function
This code does the same as the one above, but with a different approach to the problem. Looking at the differences:
In the first line, a variable of the
Controller
type is defined, and then set to
...Dataset.Controller
when the
project is loaded. The Controller is a central object that gets events for every field and document. The outcome here
is an event for every field, no matter which document type and field type.
In the event handling routine, we must therefore determine if we got the correct field by asking for the field’s name
(
Field.Name
) and for the name of the corresponding document (
Field.Document.Name
). If these are
Amount
and
Invoice
, we open the dialog box.
Which way of defining the event you prefer, depends very much on the project: Suppose there are many different
form types, all of them having an
Amount
field, and the same code should be executed if any of these fields
change. Then here to define an event handling function for every single form type would be tedious, so you would
prefer the second method. On the other hand, if only a specialized behavior for an index field on a special form type
is desired, the first method is more convenient.
As you will see later on, there is also something in between these two methods: You can also use the
DocumentType
’s
FieldChanging
event, which would get an event for all fields of a certain document type.
These two short examples might have given you an idea how to do scripting. The next chapters will go more into the
details.