Examples: Events

  1. This LotusScript event executes when a database opens. It opens a particular view depending on the value of the OrgUnit1 part of the user's name.
    Sub Postopen(Source As Notesuidatabase)
         Dim session As New NotesSession
         Dim userName As NotesName
         Set userName = session.CreateName(session.UserName)
         Select Case userName.OrgUnit1
         Case "Marketing"
              Call Source.OpenView("Marketing")
         Case "Engineering"
              Call Source.OpenView("Engineering")
         Case Else
              Call Source.OpenView("General")
         End Select
    End Sub
  2. This LotusScript event executes before the Engineering view opens. If the OrgUnit1 part of the user's name is not "Engineering," the script displays a message and sets Continue to False so that the view does not open.
    Sub Queryopen(Source As Notesuiview, Continue As Variant)
         Dim session As New NotesSession
         Dim userName As NotesName
         Set userName = session.CreateName("session.UserName")
         If userName.OrgUnit1 <> "Engineering" Then
              Continue = False
              Messagebox  _
              "This view is reserved for engineering",, _
              "No admittance"
         End If
    End Sub
  3. This LotusScript event executes when the user opens a document. The document goes into Edit mode even if the user doesn't open it that way, the ruler opens, and all sections expand.
    Sub Postopen(Source As Notesuidocument)
         source.EditMode =  True
         source.Ruler = True
         Call source.ExpandAllSections
    End Sub
  4. This JavaScript button script alters the value of one of the fields on the associated form. In this example, a document can be assigned a priority rating from 1 to 10, with 1 being the highest priority. The document's priority rating is held in a field called "Priority" on the form. The button "Increase Priority" allows users to increase the priority without the need to edit the field directly. When the button is clicked, the Priority field's value is decreased by 1, assigning it a higher priority rating. The script will not allow a priority of less than 1 to be assigned.
    //get a handle to the Priority field
    var priorityField = document.forms[0].Priority;
    //get its current integer value
    var currentPriority = parseInt(priorityField.Value);
    //increase the priority (1 is the highest, 10 is the lowest)
    var newPriority = Math.max(currentPriority -1, 1);
    //update the Priority field value
    priorityField.value = newPriority;
  5. This LotusScript event executes when the user enters the FullName field. The script fills in the FullName field by concatenating the FirstName field, a space, and the LastName field.
    Sub Entering(Source As Field)
         Dim workspace As New NotesUIWorkspace
         Dim uidoc As NotesUIDocument
         Set uidoc = workspace.CurrentDocument
         firstName = uidoc.FieldGetText("FirstName")
         lastName = uidoc.FieldGetText("LastName")
         fullName = firstName & " " & lastName
         Call uidoc.FieldSetText("FullName", fullName)
    End Sub
  6. This JavaScript event executes when the focus moves away from the field. The script trims the white space from the start and end of the field and then tests whether the value is a valid zip code. If it is invalid, a message is displayed in the status bar and the focus is set back onto the field itself. Note that "trim" and "isValidZipCode" are user-defined functions that must be available from within the onBlur handler.
    var zipCode = trim(this.value);
    if(!isValidZipCode(zipCode)){
      window.status = "Illegal zip code.";
      this.focus();
    }
  7. This LotusScript event executes when the user exits from the Age field. The script forces the user to enter a numeric value.
    Sub Exiting(Source As Field)
         Dim workspace As New NotesUIWorkspace
         Dim uidoc As NotesUIDocument
         Set uidoc = workspace.CurrentDocument
         age = uidoc.FieldGetText("Age")
         If age = "" Or Not Isnumeric(age) Then
              While age = ""
                   age = Inputbox _
                        ("Whoa! you must enter an age")
              Wend
              While Not Isnumeric(age)
                   age = Inputbox("Age must be numeric")
              Wend
              Call uidoc.FieldSetText("Age", age)
         End If
    End Sub
  8. This LotusScript event executes when the user exits from a field. The script sends a mail message to Mary Chen.
    Sub Exiting(Source As Field)
         Dim session As New NotesSession
         Dim db As NotesDatabase
         Set db = session.CurrentDatabase
         Dim doc As New NotesDocument(db)
         doc.Form = "Form"
         doc.Subject = "Sales Updated"
         doc.Body = "Sales updated by " & session.UserName
         Call doc.Send(True, "Mary Chen")
    End Sub