Examples: Getting an item and its values

  1. This example uses the Items property of NotesDocument to get each item in each document in a database view, and displays its name and text representation.
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set view = db.GetView("By Category")
      Set doc = view.GetFirstDocument
      While Not(doc Is Nothing)
        Forall item In doc.Items
          Messagebox item.Name & " = " & item.Text
        End Forall
        Set doc = view.GetNextDocument(doc)
      Wend
    End Sub
  2. This example uses the GetFirstItem method of NotesDocument to get the Subject item in each document in a database view, and displays its name and text value.
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim item As NotesItem
      Set db = session.CurrentDatabase
      Set view = db.GetView("By Category")
      Set doc = view.GetFirstDocument
      If doc.HasItem("Subject") Then
        While Not(doc Is Nothing)
          Set item = doc.GetFirstItem("Subject")
          Messagebox item.Name & " = " & item.Text
          Set doc = view.GetNextDocument(doc)
        Wend
      End If
    End Sub
  3. This example uses the item name as a document property to get the value of the Categories item in each document in a database.
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set view = db.GetView("By Category")
      Set doc = view.GetFirstDocument
      If doc.HasItem("Categories") Then
        While Not(doc Is Nothing)
          Forall category In doc.Categories
            Messagebox category
          End Forall
          Set doc = view.GetNextDocument(doc)
        Wend
      End If
    End Sub
  4. This example uses the GetItemValue method of NotesDocument to get the value of the Subject item in each document in a database.
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set view = db.GetView("By Category")
      Set doc = view.GetFirstDocument
      If doc.HasItem("Subject") Then
        While Not(doc Is Nothing)
          Forall subject In _
          doc.GetItemValue("Subject")
            Messagebox subject
          End Forall
          Set doc = view.GetNextDocument(doc)
        Wend
      End If
    End Sub
  5. This example tests for the presence of a specified item in each document in a view.
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set view = db.GetView("By Category")
      itemName = Inputbox("Name of item?")
      Set doc = view.GetFirstDocument
      While Not(doc Is Nothing)
        If doc.HasItem(itemName) Then
          Messagebox "Item present in document"
        Else
          Messagebox "Item not present in document"
        End If
        Set doc = view.GetNextDocument(doc)
      Wend
    End Sub
  6. This agent demonstrates a work-around for accessing multiple items with the same name. This is a work-around and creating multiple items with the same name is not recommended.

    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim item As NotesItem
      Set db = session.CurrentDatabase
      Set dc = db.UnprocessedDocuments
      Set doc = dc.GetFirstDocument
      REM Get first FooBar item
      Set item = doc.GetFirstItem("FooBar")
      While Not(item Is Nothing)
        Messagebox item.Text,, item.Name
        REM Remove item from memory
        Call item.Remove
        REM Get next FooBar item
        Set item = doc.GetFirstItem("FooBar")
      Wend
    End Sub