Identify duplicate documents in a view

This agent code loops each document in the specified view, compares the values of each doc to the next doc in the view. The view must be sorted by atleast the first value you are comparing. The example below looks for duplicate assignment documents for the same employee.
Lotus Notes View • LotusScript


Sub Initialize
	
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Set db = session.CurrentDatabase
	
	Dim view As NotesView
	Set view = db.GetView("AssignmentStubs")
	
	Dim doc1 As NotesDocument
	Set doc1 = view.GetFirstDocument
	
	Dim doc2 As NotesDocument
	Set doc2 = view.GetNextDocument(doc1)
	
	Dim DocCounter As Long
	DocCounter = 1
	Dim ErrorCounter As Long
	
	Do  
		
		If doc1.EmployeeUniqueID(0) = doc2.EmployeeUniqueID(0) Then
			If doc1.HostAssignmentID(0) = doc2.HostAssignmentID(0) Then
				Msgbox "The is a duplicate assignment stubs for " & doc1.EmployeeUniqueID(0) , 0 + 64 , "Duplicate Found"
				ErrorCounter = ErrorCounter + 1
			End If
		End If
		
		Set doc1 = doc2
		Set doc2 = view.GetNextDocument(doc1)
		
		DocCounter = DocCounter + 1
		
		Print DocCounter & " assignment stubs compared ~ " & ErrorCounter & " errors found"
		
	Loop Until doc2 Is Nothing
	
	Print "Done"
	
End Sub

Posted by fbrefere001 on Friday April 12, 2002