Examples: Remove method (NotesNoteCollection - LotusScript®)

This agent builds a note collection of documents from the current database. It removes any document with a subject containing the text "test" then exports the revised collection as DXL to the file filename. A string representing the note ID is used as the method parameter.

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