Examples: PostOpen event

  1. This script checks if the current document's CheckedOut field contains "Yes." If so, it displays a message telling the user that the document is checked out.
    Sub Postopen(Source As Notesuidocument)
      If ( source.FieldGetText( "CheckedOut" ) = "Yes" ) Then
        Messagebox("This document is currently checked out.")
      End If
    End Sub
  2. This script checks if the user has created a new document. If so, it puts a new value in the ProblemHistory field that records when the problem report was created.
    Sub Postopen(Source As Notesuidocument)
      Dim dateTime As New NotesDateTime( "Today" )
      If source.IsNewDoc Then
        Call source.FieldSetText _
        ( "ProblemHistory", _
        "Problem opened on " & dateTime.LocalTime )
      End If
    End Sub
  3. This script checks if the user has opened an Employee Request document in Edit mode. If so, it guides the user through the document, based on the contents of the Owner field. The document is completed in three stages:
    • The employee enters the request. If the Owner field contains "Employee," the script prompts the employee for the text of the request. The Owner field is changed to "Manager," and the document is saved and closed.
    • The manager approves or rejects the request. If the Owner field contains "Manager," the script displays a dialog box with Yes and No buttons, asking the Manager if she approves the request. The Status field gets set to either "Approved" or "Rejected," the Owner field is changed to "Human Resources," and the document is saved and closed.
    • The Human Resources person approves or rejects the Manager's decision. If the Owner field contains "Human Resources," the script displays a dialog box with Yes and No buttons, asking the Human Resources person if he approves the Manager's decision. The Confirmation field gets set to either "Approved" or "Rejected," and the document is saved and closed.

    This script must include the file LSCONST.LSS in order to work properly.

    Sub Postopen(Source As Notesuidocument)
      Dim ownerType As String
      Dim employeeRequest As String
      Dim result As Integer
      If source.EditMode Then
        ownerType = source.FieldGetText( "Owner" )
        Select Case ownerType
        ' 1. Employee enters the request in a dialog box
        Case "Employee":
          employeeRequest = Inputbox$ _
          ( "Please enter your request", "Request" )
          Call source.FieldSetText("Request", employeeRequest)
          Call source.FieldSetText("Owner", "Manager")
                   
         ' 2. Manager approves or rejects the request
        Case "Manager":
          result = Messagebox _
          ( "Do you approve this employee's request?", _
          MB_YESNO, "Approve" )
          If ( result = IDYES ) Then
            Call source.FieldSetText( "Status", "Approved" )
          Else
            Call source.FieldSetText( "Status", "Rejected" )
          End If
          Call source.FieldSetText("Owner", "Human Resources")
                   
        ' 3. Human Resources approves or rejects
        ' the Manager's decision
        Case "Human Resources":
          result = Messagebox _
          ( "Do you approve this manager's decision?", _
          MB_YESNO, "Confirm" )
          If ( result = IDYES ) Then
            Call source.FieldSetText _
            ( "Confirmation", "Approved" )
          Else
            Call source.FieldSetText _
            ( "Confirmation", "Rejected" )
          End If
        End Select
              
        ' After each step, the document is saved and closed
        Call source.Save
        Call source.Close
      End If
    End Sub