Manage Learn to apply best practices and optimize your operations.

Delete a collection of documents

How to exclude documents in a collection that will cause an error when a user tries to delete the collection.

You will always have a problem when deleting a collection of documents. When a user executes a deletion agent on a collection of documents and if some of those documents were open or the user was not permitted (for any reason) to delete them, the user will get an error.

To prevent the error, you have several ways to exclude these documents, but you will always have the problem of setting the collection pointer to the correct position. By several trials, I found the most portable, handy and efficient way to avoid these problems.

Sub DeleteDocuments
 Dim s As New NotesSession
 Dim db As NotesDatabase
 Dim dc As NotesDocumentCollection
 Dim doc As NotesDocument
 Dim ExecludedDocs() As NotesDocument
 Dim x As Long, y As Long, Cond As Boolean
 
 Set db = s.CurrentDatabase
 Set dc = db.UnprocessedDocuments
 
 REM Using GetFirstDocument and 
GetNextDocument methods
 REM are much faster when you have 
high number of documents
 y = 0
 Redim ExecludedDocs(y)
 Set doc = dc.GetFirstDocument
 For x = 1 To dc.Count
  Cond = True  'you set here the exclusion 
condition such as doc.IsUIDocOpen
 or Not doc.IsValid
  If Cond Then
   'add the execluded document to an 
array of documents
   Redim Preserve ExecludedDocs(y)
   Set ExecludedDocs(y) = doc
   y = y + 1
  End If
  
  'do any required processes here
  '
  '
  'you may not delete the document here,
 that makes the next doc not available.
  Set doc = dc.GetNextDocument(doc)
 Next
 
 If y > 0 Then 'we have excluded docs
  'Remove them from collection
  Forall exdoc In ExecludedDocs
   Set exdoc = dc.GetDocument(exdoc)
   Call dc.DeleteDocument(exdoc)
  End Forall
 End If
 
 'now remove the collection safely
 Print "deleting documents, please wait..."
 Call dc.RemoveAll(True)
 Print
End Sub

Do you have comments on this tip? Let us know.

Dig Deeper on Lotus Notes Domino Agents

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close