Siebel CRM Desktop for IBM Notes Administration Guide > Customizing Siebel CRM Desktop > Validating the Data That Users Enter >

Creating Custom Validations


You can create a custom validation.

To create custom validations

  1. Make sure the InitValidators procedure is defined in the class that the form references.

    For more information, see Preparing to Use Validation.

  2. Open IBM Domino Designer, open the SBL.Forms script library, and then add the following code to the class that the form references:

    vld.ValidateCustom ids_array_ex, validation_message, validation_callback, ""

    where:

    • ids_array_ex identifies an ArrayEx of control identifiers that CRM Desktop highlights in the client if the validation fails.
    • validation_message is a string constant that contains the message that CRM Desktop displays in the client if the validation fails.
    • validation_callback identifies the instance of the class that this code inherits from the CallBackValidation class. This class overrides the Validate function of the base class. The function gets the ValidationContext object as input and allows it to access data and to access the user interface document, which is a form in IBM Domino Designer. If the validation is successful, then it returns a value of true.

      For more information, see Opening IBM Domino Designer.

  3. Test your changes and then republish the customization package.

    For more information, see Republishing Customization Packages.

Example of Creating a Custom Validation

If the user enters a new opportunity, then the following code makes sure the close date that the user enters occurs later than the current date:

Dim ValidationCallBackCloseDate As New ValidationOpportunityCloseDate(NewSmartArray().Add("CloseDateOnly"))
vld.ValidateCustom NewSmartArray().Add("CloseDateOnly"), MSG_OPPORTUNITY_CLOSE_DATE_PASSED_OUT, ValidationCallBackCloseDate, ""

To do the validation, this code calls the following ValidationOpportunityCloseDate class:

Private Class ValidationOpportunityCloseDate As CallbackValidation
  Sub New(Fields As ArrayEx)
    Set m_Fields = Fields
  End Sub

  'Validate - validation implementation
  Function Validate(validationCtx As ValidationContext) As Boolean
    Dim Doc As DocumentEx
    Dim SavedDoc As DocumentEx
    Dim Item As Variant
    Dim EnteredDate As NotesDateTime
    Dim OriginalDate As NotesDateTime
    Dim CurrentDate As NotesDateTime
    Dim Field As String
    Dim i As Integer
    Dim DateWasNotChanged As Boolean

    Set Doc = validationCtx.DocEx
    Set SavedDoc = validationCtx.DocBackendEx
    Set CurrentDate = New NotesDateTime("")
    CurrentDate.Setnow

    Validate = True
    For i = 0 To m_Fields.Length - 1
      Field = m_Fields.Item(i)

      Set Item = Doc.FirstItem(Field)
      Set EnteredDate = New NotesDateTime(Item.Text)
      Set Item = SavedDoc.FirstItem(Field)
      DateWasNotChanged = False
      If Not Item Is Nothing Then
        Set OriginalDate = New NotesDateTime(Item.Text)
        DateWasNotChanged = (EnteredDate.Timedifference(OriginalDate) = 0)
      End If

      If EnteredDate.IsValidDate Then
        Validate = DateWasNotChanged Or (EnteredDate.TimeDifference(CurrentDate) >= 0)
      End If

      If Validate = False Then
        Exit For
      End If
    Next
  End Function
End Class

Siebel CRM Desktop for IBM Notes Administration Guide Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.