次のエージェントは現在のデータベース内の文書を使用して、文書コレクションをビルドします。エージェントはまず「test」という文字列を含む件名を持つ文書をすべて削除し、修正後のコレクションを DXL としてファイル filename にエクスポートします。Remove メソッドのパラメータには、文書 ID を表す文字列を指定します。
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim stream As NotesStream
Dim exporter As NotesDXLExporter
Dim nc As NotesNoteCollection
Dim nid As String, nextid As String 'note IDs
Dim i As Integer
Dim doc As NotesDocument
Dim subj As Variant
Dim filename As String 'output file
REM Create note collection
Set db = session.CurrentDatabase
path$ = "c:¥dxl¥"
filename$ = Left(db.FileName, Len(db.FileName) - 3) & "dxl"
filename$ = path$ & filename$
Set nc = db.CreateNoteCollection(False)
nc.SelectDocuments = True
Call nc.BuildCollection
REM Modify the collection - take out test documents
nid = nc.GetFirstNoteId
For i = 1 To nc.Count
'get the next note ID before removing any notes
nextid = nc.GetNextNoteId(nid)
Set doc = db.GetDocumentByID(nid)
subj = doc.GetItemValue("Subject")
If Not findTest(subj(0))(0) = 0 Then
Messagebox subj(0), , "removing document"
Call nc.Remove(nid)
End If
nid = nextid
Next
REM Export note collection as DXL
Set stream = session.CreateStream
If Not stream.Open(filename) Then
Messagebox "Cannot open " & filename,, "Error"
Exit Sub
End If
Call stream.Truncate
Set exporter = session.CreateDXLExporter(nc, stream)
Call exporter.Process
Messagebox filename, , "updated collection written to"
End Sub
Function findTest(value As String)
findTest = Evaluate( "@Contains (""" _
+ Ucase$(value) _
+ """; """ _
+ "TEST"+""") ")
End Function