例: Creating an item and assigning values

  1. 次の例は、NotesItem クラスの New メソッドを使用して、データベースの各文書に ModifiedBy という名前の新規アイテムを追加し、Notes セッションのユーザー名を値として代入します。
    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.AllDocuments
      Set doc = dc.GetFirstDocument()
      While Not(doc Is Nothing)
        Set item = New NotesItem _
        (doc, "ModifiedBy", session.UserName)
        Call doc.Save(True, False)
        Set doc = dc.GetNextDocument(doc)
      Wend
    End Sub
  2. 次の例では、NotesDocument クラスの AppendItemValue メソッドを使用して、データベースの各文書に ModifiedBy という名前の新規アイテムを追加し、Notes セッションのユーザー名を値として代入します。
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set dc = db.AllDocuments
      Set doc = dc.GetFirstDocument()
      While Not(doc Is Nothing)
        Call doc.AppendItemValue _
        ("ModifiedBy", session.UserName)
        Call doc.Save(True, False)
        Set doc = dc.GetNextDocument(doc)
      Wend
    End Sub
  3. 次の例では、NotesItem クラスの Values プロパティを使用して、データベースの各文書の ModifiedBy という名前のアイテムの値を変更します。名前が ModifiedBy であるすべてのアイテムのすべての値にアクセスするために、ループを使用します。
    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.AllDocuments
      Set doc = dc.GetFirstDocument
      While Not(doc Is Nothing)
        docItems = doc.Items
        Forall docItem In docItems
          If docItem.Name = "ModifiedBy" Then
            itemValues = docitem.Values
            Forall itemValue In itemValues
              itemValue = "Anonymous"
            End Forall
            docItem.Values = itemValues
          End If
        End Forall
        Call doc.Save(True, False)
        Set doc = dc.GetNextDocument(doc)
      Wend
    End Sub
  4. 次の例では、NotesDocument クラスの ReplaceItemValue メソッドを使用して、データベースの各文書の ModifiedBy という名前のアイテムの値を変更します。この結果、各文書には ModifiedBy という名前のアイテムは 1 つになりその値も 1 つとなります。
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set dc = db.AllDocuments
      Set doc = dc.GetFirstDocument()
      While Not(doc Is Nothing)
         Call doc.ReplaceItemValue _
         ("ModifiedBy", "Anon3")
         Call doc.Save(True, False)
         Set doc = dc.GetNextDocument(doc)
      Wend
    End Sub