Pages

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
    performBasicValidation=False
   
    'declare all variables and functions necessary for further manipulation
    Dim session As New NotesSession   
    Dim fields As Variant
    Dim currentField As String
   
    'initiation
    '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
    fields=Split(mandatoryFields,"$#$")
   
    Forall vall In fields
        currentField=Strright(vall,"~")
        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"
                performBasicValidation=False
                Exit Function
            End If
        End If
    End Forall
   

   
    'mark the flow of control moving out of the current function
    performBasicValidation=True
    Exit Function
    'log the errors that resulted in abrupt termination
basicValidationErrHandler:
    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.

    ReplyDelete