Tuesday, February 2, 2010

Basic Validation for fields in a form

'@Purpose    :    To perform basic validation on fields that is to check wether they are empty or not
'@Author        :    Karthikeyan A
'@Return        :    Boolean
'@Logic        :     Parameter "manadatoryFields" must contain field labels and field names seperated by "~" and each pair inturn must be seperated by "$#$"

Function performBasicValidation(mandatoryFields As String,uidoc As NotesUIDocument) As Boolean
    'mark the flow of control moving into the current function
    'declare all variables and functions necessary for further manipulation
    Dim session As New NotesSession   
    Dim fields As Variant
    Dim currentField As String
    'handle errors in case of abrupt termination
    On Error Goto basicValidationErrHandler
    'process the provided list of mandatory fields and values to check if they have some value or not
    Forall vall In fields
        If Not currentField="" Then
            If Trim(Replace(Replace(uidoc.FieldGetText(currentField),Chr(10),""),Chr(13),""))="" Then
                Call uidoc.GotoField(currentField)
                Msgbox "Please provide the" &Cstr(Strleft(vall,"~")) & Chr(13) & "Note: All fields marked with * are Mandatory",,"Information required"
                Exit Function
            End If
        End If
    End Forall

    'mark the flow of control moving out of the current function
    Exit Function
    'log the errors that resulted in abrupt termination
    Msgbox "An error occured while attempting to validate the document ",,"Validation failed"
    Print "Error : " & Error & " occured on line " & Cstr(Erl) & " with error number " & Cstr(Err) & " in basic validation while processing field ***" & currentField & "***"
    Exit Function
End Function

1 comment:

  1. In order to use the "performBasicValidation" function, Consider the following as a Sample

    Sub Querysave(Source As Notesuidocument, Continue As Variant)
    Dim x As String
    x = "test~lstIndustry$#$"
    Call performBasicValidation(x,Source)

    End Sub

    Hope this is useful.