Subject: Example of QuerySave validation
In this example, all of the required fields are stored in a workflow profile document that is looked up to based on the given state of a document. This example is before I have moved the validation to a script library, hence the length of the code:
Sub Querysave(Source As Notesuidocument, Continue As Variant)
'GET A HANDLE ON THE CURRENT DOCUMENT
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set db=session.currentdatabase
Set uidoc=ws.currentdocument
Set doc=uidoc.document
Dim strUserAbbreviate As String
Dim strName As String
Dim success As Variant
Dim vRequired As Variant
'GET A HANDLE ON THE DEFAULT WORKFLOW PROFILE DOCUMENT FOR THIS APPLICATION
Dim docWFDefaults As NotesDocument
Set docWFDefaults= getFirstDocument
(db, “luvaWFActors”)
'GET A HANDLE ON THE ACTION BEING PROCESSED
Dim strDocState As String
strDocState=uidoc.FieldGettext(“DocumentState”)
'GET A HANDLE ON THE NEWLY SELECTED ACTION SO THAT THE APPROPRIATE WORFLOW MANAGEMENT DOCUMENT CAN BE SELECTED
Dim strDocowner As String
strDocOwner=uidoc.FieldGetText(“DocumentOwner”)
'CALL THE getSelectedAction FUNCTION FROM THE SCRIPT LIBRARY TO GET THE VALUE FOR THE CURRENT ACTION bEING PROCESSED
Dim strSelectedAction As String
strSelectedAction=getSelectedAction (db, doc,
docWFDefaults, strDocState, strDocOwner,
strSelectedAction)
If strSelectedAction=“” Then
Messagebox (“You must select an action”)
continue=False
Exit Sub
End If
'THIS SECTION IS ONLY APPLICABLE TO ACTION 1
Dim strApplication As String
strApplication=uidoc.FieldGettext(“Application”)
If strApplication=“ApplicationName” Then
If strSelectedAction="Request Sent to
Production System" And
doc.CIOApprovedFlag(0)="" Then
Messagebox ("This must be sent to the CIO
for approval before it can be sent to
production.")
continue=False
Exit Sub
End If
If doc.tmpPriorAction(0) <> "Request
Successful on error checking System by
Requester" And strSelectedAction=
"Request Sent To CIO for Approval" Then
Messagebox ("This action cannot be sent to
the CIO until you have been notified by the
PM that it is ready for production.")
continue=False
Exit Sub
End If
End If
'GET THE WORKFLOW DOCUMENT ASSOCIATED WITH THE NEWLY SELECTED ACTION
If (strDocState <> strSelectedAction) Then
Dim docNewWorkflow As NotesDocument
Call GetWorkflowDocument(db, docNewWorkflow,
strSelectedAction )
If Not (docNewWorkflow Is Nothing) Then
Print(“Worflow Document Opened”)
'VALIDATE REQUIRED FIELDS ON THE REQUEST INFORMATION TAB OF THE FORM. IN ORDER TO MIMIC THE BEHAVIOR 'OF A QUERY SAVE AGENT, THE ROUTINE HAS BEEN WRITTEN THIS WAY
If strSelectedAction=
docWFDefaults.admWFDefaultAction(0) Then
Call CreateUserProfile(uidoc)
If Not (docNewWorkflow.HasItem
(“admValidateText”)) Then
Print(“admValidateText not found”)
Else
Dim strField As String
Dim strErrorMessage As String
vRequired=docNewWorkFlow.GetItemValue
("admRequiredFields")
Forall f In vRequired
strField=f
strErrorMessage="You must enter a value for
the following field: " & strField
Call validateField (f, uidoc,
strErrorMessage, continue)
If Continue=False Then
Exit Sub
End If
etc etc