Manage Learn to apply best practices and optimize your operations.


Store the names of field and associated error message in a lookup document, cycle through the items for validation errors.

This code allows you to store the names of field to validate and associated error message in a lookup document then cycle through the items on a document for validation errors. All the errors are then displayed to the user on a single form.

Option Public
Option Explicit
Use "Global"
Public FieldName() As String
Public ErrorMsg() As String
Public SpecialVal() As String

Public ItemVal As Integer

Public Function DocValidation(db As NotesDatabase, doc As NotesDocument, strOption As String) As Integer
Fields to be validated stored in Lookup documents.
	Dim col As NotesDocumentCollection
	Dim resp As NotesDocument
	Dim item As NotesItem
	Dim strForm$, strItemForm$
	Dim strDisplay$, strItemDisplay
	Dim i%, intUB%	
	Dim intCounter%, intErrorCounter%
	Dim msg$()
	Dim varReturn
	Dim strMacro$
	DocValidation = 0
	intCounter = 0
	'use event type to build key fo DBLookup
	Set item = doc.GetFirstItem(ETYPE)
	If Not (item Is Nothing) Then
		strForm = item.Values(0)
	End If
	'build display value for error form
	Set item = doc.GetFirstItem(TRACK)
	If Not (item Is Nothing) Then
		strDisplay = "#" & item.Text & " -- "
	End If
	Set item = doc.GetFirstItem(DESC)
	If Not (item Is Nothing) Then
		strDisplay = strDisplay & item.Text
	End If
	'load field names and error messages for both the header and the item check
	Call LoadValues(db, strForm, strOption)	
	'validate event header
	intUB = Ubound(FieldName)
	For i = 0 To intUB
		Set item = doc.GetFirstItem(FieldName(i))
		If item Is Nothing Then
				'if item doesn't exist, that means it wasn't filled out and should have been so
				'retrieve validation message to display
			intCounter = intCounter + 1
			Redim Preserve msg(intCounter)
			msg(intCounter-1) = ErrorMsg(i)
		Else	'if the item is there, see it it's got a value
			If Len(Trim(item.Text)) = 0 Then
				intCounter = intCounter + 1
				Redim Preserve msg(intCounter)
				msg(intCounter-1) = ErrorMsg(i)

			End If
		End If
	Next	'fieldname

	'create error message box	
	If intCounter > 0 Then
		Call DisplayError(db, msg, strDisplay)
		Exit Function
		DocValidation = True
	End If

End Function
Private Sub LoadValues(db As NotesDatabase, strForm$, strOption$)
NOTE:  Can't use DBLookup function because collecting AllDocumentsByKey not just one

	Dim valcol As NotesDocumentCollection
	Dim view As NotesView	
	Dim valdoc As NotesDocument
	Dim item As NotesItem
	Dim strKey$
	Dim intCount%, i%, intUB%
	'initialize item validation flag
	ItemVal = True
	'construct keys
	strKey = "_VALIDATION*"&strForm & strOption
	'collect validation documents
	Set view = db.GetView(cLOOKUP2)
	Set valcol = view.GetAllDocumentsByKey(strKey)
	intCount = valcol.Count
	If intCount > 0 Then
		i = 0
		intUB = intCount -1
		Redim FieldName(intUB)
		Redim ErrorMsg(intUB)
		Set valdoc = valcol.GetFirstDocument
		While Not (valdoc Is Nothing)
			FieldName(i) = valdoc.GetItemValue("Field_1")(0)
			ErrorMsg(i) = valdoc.GetItemValue("Field_2")(0)
			Set valdoc = valcol.GetNextDocument(valdoc)
			i = i +1
		'set flag to not perform item validation
		ItemVal = False		
	End If
End Sub
Private Function DisplayError(db As NotesDatabase, msg, strDisplay, eventdoc As NotesDocument) As Integer
	Dim uiw As New NotesUIWorkspace
	Dim uidoc As NotesUIDocument
	Dim errorDoc As NotesDocument
	Dim Item As NotesItem
	Dim flag
	Set errorDoc = db.CreateDocument
'	errorDoc.Form = "Error"
	Call errorDoc.ReplaceItemValue("Display", strDisplay)
	Set item = New NotesItem(errorDoc,"DocErrors", msg)
	flag = uiw.DialogBox("Error", True, True, False, True, True, True, "Validation error...", errorDoc)
	If flag Then
		Set uidoc = uiw.EditDocument(True, eventdoc)	
		DisplayError =2
		DisplayError =1
	End If
End Function

Dig Deeper on Domino Resources

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...