Examples: HasItem method

  1. This script displays a message about a document.
    Dim doc As NotesDocument
    '...set value of doc...
    If doc.HasItem( "Subject" ) Then
      Messagebox _
      ( "There is a Subject item on this document." )
      Messagebox _
      ( "There is no Subject item on this document." )
    End If
  2. This example shows how you can use HasItem and AppendItemValue together. Suppose you have a discussion database with Main Topics and Responses. After users have created and saved several documents, you decide that the Response documents should store the original Subject from the Main Topic, as well as their own Subject.

    You create an OriginalSubject field on the Response form that inherits its value from the Subject field of the Main Topic. This works nicely, but you still have several Response documents with no value for Original Subject. You write this script to remedy the situation. It uses HasItem to check every Response in the main view of the current database for an item called OriginalSubject. If HasItem returns False, it uses AppendItemValue to create an item called OriginalSubject.

    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim view As NotesView
    Dim mainDoc As NotesDocument
    Dim responseDoc As NotesDocument
    Set db = session.CurrentDatabase
    Set view = db.GetView( "Main View" )
    ' get the first document in the view, which is a Main Topic
    Set mainDoc = view.GetFirstDocument
    ' visit every Main Topic in the view
    While Not ( mainDoc Is Nothing )
      ' get the first response to the Main Topic
      Set responseDoc = view.GetChild( mainDoc )
      ' visit every response to the Main Topic
      While Not ( responseDoc Is Nothing )
        If Not (responseDoc.HasItem("OriginalSubject")) Then
          ' copy the Main Topic's Subject item into the 
          ' Response's OriginalSubject item
          Call responseDoc.AppendItemValue _
          ( "OriginalSubject", _
          mainDoc.GetItemValue( "Subject" ) )
          Call responseDoc.Save( True, False )
        End If
        ' get the next response to the Main Topic
        Set responseDoc = view.GetNextSibling( responseDoc )
      ' get the next Main Topic
      Set mainDoc = view.GetNextSibling( mainDoc )