Examples: OnLoad event

  1. This OnLoad event displays a message if the current document's CheckedOut field contains "Yes."
    Sub Onload(Source As Notesuidocument)
      If (Source.FieldGetText("CheckedOut") = "Yes") Then
        Messagebox "This document is checked out",, "Check out"
      End If
    End Sub
  2. This OnLoad event writes the time to the ProblemHistory field if the current document is new.
    Sub Onload(Source As Notesuidocument)
      Dim dateTime As New NotesDateTime("Today")
      Call dateTime.SetNow
      If Source.IsNewDoc Then
        Call Source.FieldSetText _
        ("ProblemHistory", _
        "Problem opened on " & dateTime.LocalTime)
      End If
    End Sub
  3. This OnLoad event processes a document opened for editing in three stages:
    • If the Owner field contains "Employee," the event gets the Request field text and changes the Owner field to "Manager."
    • If the Owner field contains "Manager," the event gets the value "Approved" or "Rejected" for the Status field and changes the Owner field to "HR."
    • If the Owner field contains "HR," the event gets the value "Approved" or "Rejected" in the Confirm field.
      %INCLUDE "lsconst.lss"
      
      Sub Onload(Source As Notesuidocument)
        Dim ownerType As String
        Dim employeeRequest As String
        If Source.EditMode Then
          ownerType = Source.FieldGetText("Owner")
          Select Case ownerType
          Case "Employee"
            employeeRequest = Inputbox$ _
            ("Enter your request", "Request")
            Call Source.FieldSetText("Request", employeeRequest)
            Call Source.FieldSetText("Owner", "Manager")
          Case "Manager"
            If Messagebox _
            ("Do you approve this request?", _
            MB_YESNO, "Approve") = IDYES Then
              Call Source.FieldSetText  ("Status", "Approved")
            Else
              Call Source.FieldSetText("Status", "Rejected")
            End If
            Call Source.FieldSetText("Owner", "HR")
          Case "HR"
            If Messagebox _
            ("Do you confirm this decision?", _
            MB_YESNO, "Confirm") = IDYES Then
              Call Source.FieldSetText("Confirm", "Approved")
            Else
              Call Source.FieldSetText("Confirm", "Rejected")
            End If
          End Select
          Call Source.Save
          Call Source.Close
        End If
      End Sub