Validation function

has anyone got a lotus validation script for verifying a blank value in QuerySave?

Subject: validation function

If I understand what you’re after this may help?

Build a function in your script library that you then call from query save? You still need input translation “@Trim(@ThisValue)” on the fields in the form to prevent spaces being used as valid characters

Call your function and check for whatever you want, ie nulls, numbers over a certain value, dates in the past etc… Has the benefit of advising users about all “bad” fields in one go

Sub Querysave(Source As Notesuidocument, Continue As Variant)

If Not ValidateDocument(source.document) Then continue = False

End Sub

Function ValidateDocument(doc) As Variant

’ this routine sets the ‘uidoc’ as the current document by using a case statement

'all of the required fields are then checked and the querysave event is terminated if they’re not completed

Dim session As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim database As NotesDatabase

Dim uidoc As NotesUIDocument

Dim errors As String

Const MB_ICONSTOP = 16          ' Critical message



Set uidoc = workspace.CurrentDocument

Set database = session.currentdatabase



Select Case doc.Form(0)

Case "YourForm"

	If doc.FieldToValidate1(0) = "" Then

		errors = errors + "  Your field 1" &  Chr(9) & "(a value is required)" + Chr$(13)

	End If

	If doc.FieldToValidate2(0) = "" Then

		errors = errors + "  Your field 2" &  Chr(9) & "(a value is required)" + Chr$(13)

	End If

	

Case "YourOtherForm"

	If doc.FieldToValidate3(0) = "" Then

		errors = errors + "  Your field 3" &  Chr(9) & "(a value is required)" + Chr$(13)

	End If

End Select		



If errors >< "" Then

	Messagebox "The following field(s) are blank or contain incorrect values:" + Chr$(13) + Chr$(13)_

	+ errors + Chr$(13) + "Please ensure all the fields are complete and try again"_

	, MB_ICONSTOP, database.title

	Call uidoc.Refresh

	ValidateDocument = False

else

ValidateDocument = True

End If

End Function

Subject: RE: validation function

Do I replace: 1. “YourFrom” with the name of the form?

  1. FieldToValidate1(0) with the actual field name

  2. Anything else I have to replace?

Subject: RE: validation function

  1. Yes, use the name of your form here2. Yes, the actual field name needs to be inserted

with any luck, that should be all you need to do. Let me know how you get on…