例: Events

  1. 次の LotusScript はデータベースが開いたときに実行されます。ユーザー名の OrgUnit1 部分の値に応じて特定のビューを開きます。
    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. 次の LotusScript は [Engineering] ビューを開く前に実行されます。ユーザー名の OrgUnit1 部分が「Engineering」でない場合、スクリプトはメッセージを表示して、ビューを開かないように [Continue] に [False] を設定します。
    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. 次の LotusScript は、ユーザーが文書を開いたときに実行されます。文書は自動的に編集モードになり、ルーラーが表示され、すべてのセクションが展開されます。
    Sub Postopen(Source As Notesuidocument)
         source.EditMode =  True
         source.Ruler = True
         Call source.ExpandAllSections
    End Sub
  4. 次の JavaScript のボタンスクリプトは、関連付けられたフォーム上の 1 つのフィールドの値を変更します。この例では、文書には 1 から 10 までの優先順位 (1 が最高) を割り当てることができます。文書の優先順位は、フォーム上の [Priority] フィールドに保持されます。ボタン「Increase Priority」を使用すれば、フィールドを直接的に編集しなくても、ユーザーは優先順位を上げることができます。ボタンがクリックされると、[Priority] フィールドの値から 1 が減り、1 つ高い優先順位が割り当てられます。1 より小さい優先順位は使用できません。
    //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. 次の LotusScript のイベントは、ユーザーが [FullName] フィールドに挿入点を移動したときに実行されます。このスクリプトは、[FirstName] フィールド、空白、[LastName] フィールドを連結して [FullName] フィールドに入力します。
    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. 次の JavaScript のイベントは、フィールドからフォーカスが移動したときに実行されます。このスクリプトはフィールドの先頭と末尾の空白を切り捨て、値が有効な郵便番号かどうかテストします。無効であれば、ステータスバーにメッセージが表示され、フォーカスはフィールドに戻ります。「trim」と「isValidZipCode」はユーザー定義の関数で、onBlur ハンドラ内で有効です。
    var zipCode = trim(this.value);
    if(!isValidZipCode(zipCode)){
      window.status = "Illegal zip code.";
      this.focus();
    }
  7. 次の LotusScript のイベントは、ユーザーが [Age] フィールドの入力を終了したときに実行されます。このスクリプトはユーザーに数値の入力を求めます。
    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. 次の LotusScript のイベントは、ユーザーがフィールドの入力を終了したときに実行されます。このスクリプトは 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