例: QueryOpen event

  1. 次のスクリプトは新規文書の作成を禁止します。
    Sub Queryopen(Source As Notesuidocument, _
    Mode As Integer,  _
    Isnewdoc As Variant, Continue As Variant)
      If IsNewDoc Then
        Messagebox _
        ( "Only one Setup document is permitted" )
        continue = False
      End If
    End Sub
  2. 次のスクリプトはデータベース内に Setup 文書があるとき、新規作成を禁止します。このスクリプトは、文書が新規作成されるとき、[Setup] ビューに文書があるかどうかを調べます。ビューに既に文書があるときは、データベースに Setup 文書が存在することになるため、文書の作成は禁止されます。
    Sub Queryopen(Source As Notesuidocument, _
    Mode As Integer,  _
    Isnewdoc As Variant, Continue As Variant)
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      ' Check if the user is trying to create a new Setup doc
      If IsNewDoc Then
        Set db = session.CurrentDatabase
        Set view = db.GetView( "Setup" )
        Set doc = view.GetFirstDocument
        ' Check if a Setup doc already exists in the db
        If Not ( doc Is Nothing ) Then
          Messagebox _
          ("Only one Setup document permitted.")
          ' If so, don't let user create another one
          continue = False
        End If          
      End If
    End Sub
  3. 次のスクリプトは、ユーザーが ACL の [Supervisor] のロールのメンバーかどうかを調べます。メンバーのときは、ユーザーはこの文書を開くことができます。このロールのメンバーでないとき、またはアクセス制御リストに登録されていないとき、ユーザーはこの文書を開けません。
Sub Queryopen(Source As Notesuidocument, _
Mode As Integer,  _
Isnewdoc As Variant, Continue As Variant)
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Dim acl As NotesACL
  Dim entry As NotesACLEntry
  Set db = session.CurrentDatabase
  Set acl = db.ACL
  Set entry = acl.GetEntry( session.UserName )
  If ( entry Is Nothing ) Then
    continue = False
  Elseif Not ( entry.IsRoleEnabled( "Supervisor" ) ) Then 
    continue = False
  End If
End Sub