Help with @IsDocBeingSaved

If ONE of this three field have a value a want success, how will a do that…? And where will a put it. Is it ok if a put it in validation on SendTo-field.

@If(@IsDocBeingSaved & SendTo!= “” | CopyTo!=“” | BlindCopyTo!=“”;

@Failure("Select receiver before sending.");

@Success

)

Kind regards

David

Subject: Field Validation (Was: Help with @IsDocBeingSaved)

Hi David,

Yes - the following formula in the Input Validation for just one of the fields will work:

@If(SendTo = “” & CopyTo = “” & BlindCopyTo = “”; @Failure(“Enter at least one recipient you fool!”; @Success)

Saving will fail if they are all blank.

Validation formula are not the most elegant way of handling field validation though because they are evaluated after the QuerySave event. If you’re doing something fancy in there - perhaps prompting the user for confirmation to proceed it is annoying to the user if, after they’ve said yeah let’s do that, we then tell them they can’t because the form isn’t completed properly.

For each form, I tend to call a customised lotusscript function from QuerySave. The function evaluates to True if the fields are valid and False if they’re not. If False I prevent the save by setting the Continue variant to false.

Here is the QuerySave code:

Sub Querysave(Source As Notesuidocument, Continue As Variant)

'Continue if there are no field validation issues

If fnFieldsValid(Source) = True Then	

	Continue = True

Else 'Validation issues

	Continue = False

End If

End Sub

And the function:

Function fnFieldsValid(Source As NotesUIDocument) As Boolean

Dim s As New NotesSession	

Dim db As NotesDatabase	

Dim doc As NotesDocument

Dim strShitList As String, strFirstField As String

Dim strMsg As String, strTitle As String

Dim intProceed As Integer, intErrCount as Integer



Set db = s.CurrentDatabase

Set doc = Source.Document



'Assume everything is OK

fnFieldsValid = True



'First Check

If doc.SendTo(0) = "" And doc.CopyTo(0) = "" And doc.BlindCopyTo(0) = "" then

	'No recipient

	intErrCount = intErrCount + 1

	strShitList = strShitList + "(" + Trim(Str(intErrCount)) + ") You must enter at least one name in either the To, cc or bcc fields" + Chr(10) 'Chr(10) = Carriage Return

	If strFirstField = "" then strFirstField = "CopyTo"

	fnFieldsValid = False

End if

	



'Second Check

If doc.Field4(0) = "" Then

	intErrCount = intErrCount + 1

	strShitList = strShitList + "(" + Trim(Str(intErrCount)) + ") You must enter a value for Field4" + Chr(10)

	If strFirstField = "" Then strFirstField = "Field4"

	fnFieldsValid = False				

End If

	



If fnFieldsValid = False Then 'Tell them

	strMsg = "You have not entered one or more required values:" + Chr(10) + Chr(10)

	strMsg = strMsg + strShitList

	strMsg = strMsg + Chr(10)

	strMsg = strMsg + "Your document was NOT saved."

	strTitle = "Required Fields Not Completed"

	Messagebox strMsg, MB_OK + MB_ICONSTOP, strTitle

	

	'Go to first bad field

	If Not strFirstField = "" Then

		Source.GotoField(strFirstField)

	End If

End If

End Function

This is a simplified version if code I use in a live App and haven’t tested it with the changes. I haven’t tested the it since changing it so there may the odd typo.

HTH