Examples: Accessing agents

  1. This example indicates whether the specified agent is a Notes® agent.
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim agent As NotesAgent
      Dim nAgent As Variant
      Set db = session.CurrentDatabase
      Forall a In db.Agents
        If(a.Name = "RemoveEntry") Then
          Set agent = a
          nAgent = agent.IsNotesAgent
          If nAgent Then
            Messagebox "This is a Notes agent."
          Else
            Messagebox "This is not a Notes agent."
          End If
        End If
      End Forall
    End Sub
  2. This example indicates whether the specified agent is a Web agent.
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim agent As NotesAgent
      Dim nAgent As Variant
      Set db = session.CurrentDatabase
      Forall a In db.Agents
        If(a.Name = "Read/Write") Then
          Set agent = a
          nAgent = agent.IsWebAgent
          If nAgent Then
            Messagebox nAgent
          End If
        End If
      End Forall
    End Sub
  3. This example displays the name of the current agent.
    Sub Initialize
      Dim session As New NotesSession
      Dim agent As NotesAgent
      Set agent = session.CurrentAgent
      If Not Isempty(agent) Then
        Messagebox(agent.Name)
      Else
        Messagebox("Not an agent")
      End If
    End Sub
  4. This example displays the names of all the agents in the current database.
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Set db = session.CurrentDatabase
      agents = db.Agents
      If Not IsEmpty(agents) Then
        Forall agent In agents
          Messagebox(agent.Name)  
        End Forall
      Else
        Messagebox("No agents in database")
      End If
    End Sub
  5. This example determines if the agent "UserNameList" is triggered manually.
    Sub Initialize  
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim agent As NotesAgent
      Dim nAgent As Variant
      Set db = session.CurrentDatabase
      Forall a In db.Agents
        If(a.Name = "UserNameList") Then
          Set agent = a
          nAgent = agent.Trigger 
          If Trigger = Manual Then
            Messagebox "Trigger is Manual"
            End If
      End Forall
    End Sub
  6. This example saves data on the first invocation of an agent and displays it on every later invocation. If the agent is modified, the cycle restarts.
    Sub Initialize
      Dim session As New NotesSession
      Dim doc As NotesDocument
      Set doc = session.SavedData
      If doc.HasItem("SavedText") Then
        outText = doc.SavedText
        Messagebox("Saved text = " & outText(0))
      Else
        inText = Inputbox("Enter saved text")
        Call doc.AppendItemValue("SavedText", inText)
        Call doc.Save(True, False)
      End If
    End Sub