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

Join the conversation

1 comment

Send me notifications when other members comment.

Please create a username to comment.

I'm not real familiar with Lotus Notes and I need to be able to remove the duplicate emails before I can conutinue with the task I was given so would it be possible to get step-by-step instructions on how to create and run this View and/or Agent as I cannot seem to make it work and I'm not sure what it is that I'm doing wrong? Thanks in advance for any support that it provided.
Cancel

-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