I have a database where I want to find all the documents that have duplicates. In this case a duplicate is defined as multiple documents that have the same CompanyName and the same Country. How can I build a view that only shows the duplicates. I can get the view along with the count but can’t see to exclude the keys with a count of 1 or even if I could sort the view by the count column.
That’s right, you can’t. Documents are selected into views according to what they, themselves contain; you can’t use the content of one document to select another (except as a response).
Okay then - is there an easier way than building a view by the CompanyName + Country key; running an agent against all documents that checks this view and sets a field if duplciates found. Then I can make a view with selection formula based on this new field?
Here’s what I did to check for dups in the NAB. This is in another database that audits the NAB.
Dim dbNAB As NotesDatabase
Dim doc1 As NotesDocument
Dim doc2 As NotesDocument
Dim viewNAB As NotesView
Dim viewDup As NotesView
Dim vc As NotesViewEntryCollection
Dim ENum As String
Dim fullname1 As Variant
Dim fullname2 As Variant
Dim ENum1 As String
Dim ENum2 As String
'The info for NAB is set in the Profile document
Set dbNAB = s.GetDatabase(NABServer, NABFileName)
Set viewNAB = dbNAB.GetView(NABView)
Set viewDup = db.GetView("Duplicates")
Set doc1 = viewNAB.GetFirstDocument
Set doc2 = viewNAB.GetNextDocument(doc1)
While Not doc2 Is Nothing
fullname1 = Evaluate("@Name([CN]; FullName)", doc1)
fullname2 = Evaluate("@Name([CN]; FullName)", doc2)
eNum1 = doc1.EmployeeID(0)
eNum2 = doc2.EmployeeID(0)
If eNum1 <> "" And enum1 <> "---"Then
If eNum1 = enum2 Then
Set docDup = db.CreateDocument
docDup.Form = "Duplicates"
docDup.EmployeeID = ENum1
docDup.DisplayName = fullname1(0)
docDup.DisplayName2 = fullname2(0)
If doc2.HasItem( "$Conflict" ) Then
docDup.Comment = "Conflict"
End If
If docDup.Comment(0) = "" Then
docDup.Comment = "ENum"
Else
docDup.Comment = docDup.Comment(0) & " - " & "ENum"
End If
Call docDup.Save(True, True)
End If
End If
Set doc1= viewNAB.GetNextDocument(doc1)
Set doc2 = viewNAB.GetNextDocument(doc1)
Wend