Manage Learn to apply best practices and optimize your operations.

Another way to delete duplicate documents

This agent will delete duplicate documents with same serial number.

This member-submitted tip is an alternate way to delete duplicate documents. See also Deleting duplicate documents.

This agent will delete duplicate documents with same serial number.

Create a View Duplicate | vSerial with two columns. The first column is sorted on "SerialNo"; the second is sorted by "DateCreated" (ascending order).
 

Sub Initialize
 Dim ses As New NotesSession 
            Dim selection As String
 Dim collection As NotesDocumentCollection
 Dim doc1 as Notesdocument
 Dim doc2 as Notesdocument
 Set G_db = ses.CurrentDatabase   
 
 Dim view As NotesView
 Dim count As Integer
 Set view = G_db.GetView("vSerial")
 Set doc1 = view.getfirstdocument
 While Not (doc1 Is Nothing)
             Set doc2 = view.GetNextDocument(doc1) 
  If Not (doc2 Is Nothing) Then
   If (doc1.serialNo(0) = doc2.serialNo(0)) Then
    '----Mark Delete document to 1------------
    doc2.Mark = "1"
    Call doc2.save(true,true)
   End If
  End if
  Set doc1 = view.GetNextDocument(doc1)
 Wend

 '------Delete Document
            Dim dateTime As New NotesDateTime( "" )
 Selection = "(Form = ""FORM_NAME"" & Mark=""1"" )"
 Set collection = G_db.Search( Selection, dateTime, 0 )
 For j = 1 To collection.Count
  Set doc2 = collection.GetNthDocument( j )
                        Call doc2.remove(True) 
 Next
End Sub

MEMBER FEEDBACK TO THIS TIP

First, the RemoveAll method permanently deletes all documents in a collection from a database. Defined in

NotesDocumentCollection
Syntax
Call notesDocumentCollection.RemoveAll( force )

Second, delete duplicate documents directly. Create a View Duplicate | vSerial with two columns. The first column is sorted on "SerialNo"; the second is sorted by "DateCreated" (descending order).

Option Public
Option Explicit
Sub Initialize
 Dim ses As New NotesSession
 Dim G_db As NotesDatabase
 Dim view As NotesView
 Dim doc1 As NotesDocument
 Dim doc2 As NotesDocument
 
 Set G_db = ses.CurrentDatabase   
 
 Set view = G_db.GetView("vSerial")
 Set doc1 = view.GetFirstDocument
 While Not doc1 Is Nothing
  Set doc2 = view.GetNextDocument(doc1) 
  If Not doc2 Is Nothing Then
   If (doc1.serialNo(0) = doc2.serialNo(0)) Then
    Call doc1.Remove(True)
   End If
  End If
  Set doc1 = doc2
 Wend
End Sub

--Justin Y.

Do you have comments of your own? Let us know.

Dig Deeper on Lotus Notes Domino Agents

SearchWindowsServer

Search400

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury

SearchDataCenter

SearchContentManagement

Close