Get an email report of the differences between two documents.
Put the following code into a manually triggered agent to run on selected documents, then select the parent and conflict documents and run the agent. It will email you with a list of differences - Common fields with different values and fields that exist on only one document or the other.
Warning: This agent may not work as expected with Rich Text fields or if the documents have multiple fields with the same name.
Code
'Purpose: To analyze Save Replication conflicts and send
'an email report to the user
Dim session As New notessession
Dim db As notesdatabase
Dim coll As notesdocumentcollection
Dim parent As notesdocument
Dim child As notesdocument
Dim report As notesdocument
Dim parentitem As notesitem
Dim childitem As notesitem
Dim rtitem As notesrichtextitem
Dim itemname As String
Dim richStyle As NotesRichTextStyle
'setting values
Set db = session.currentdatabase
Set coll = db.unprocesseddocuments
Set parent = coll.getfirstdocument
Set child = coll.getnextdocument(parent)
Set report = db.createdocument
Set rtitem = New NotesRichTextItem ( report, "Body" )
Set richStyle = session.CreateRichTextStyle
'making sure that the user has selected two documents
If coll.count<>2 Then
Msgbox "Please select the two documents in question and try again."
Exit Sub
End If
'setting the first heading
Call rtitem.appendtext("Disclaimer: Please note this report tests the first occurrance of each item by name")
Call rtitem.addnewline(1)
Call rtitem.appendtext("If the documents have multiple items with the same itemname, this report may be inaccurate.")
Call rtitem.addnewline(3)
richStyle.Underline = True
richStyle.Bold = True
Call rtitem.AppendStyle(richStyle)
Call rtitem.appendtext("Items on both documents that are in conflict")
richStyle.Underline = False
richStyle.Bold = False
Call rtitem.AppendStyle(richStyle)
Call rtitem.addnewline(2)
'first check - All the common items
Forall i In parent.items
itemname = i.name
Set parentitem = parent.getfirstitem(itemname)
If child.HasItem( itemname) Then
Set childitem = child.getfirstitem(itemname)
If childitem.text<>parentitem.text Then
richStyle.Bold = True
Call rtitem.AppendStyle(richStyle)
Call rtitem.appendtext(itemname)
richStyle.Bold = False
Call rtitem.AppendStyle(richStyle)
Call rtitem.addnewline(1)
Call rtitem.appendtext(parentitem.text+" -/- "+childitem.text)
Call rtitem.addnewline(2)
End If
End If
End Forall
'setting the second heading
richStyle.Underline = True
richStyle.Bold = True
Call rtitem.AppendStyle(richStyle)
Call rtitem.addnewline(2)
Call rtitem.appendtext("Items only on the Parent Document")
richStyle.Underline = False
richStyle.Bold = False
Call rtitem.AppendStyle(richStyle)
Call rtitem.addnewline(2)
'second test - all items on the parent that aren't on the child
Forall k In parent.items
itemname = k.name
Set parentitem = parent.getfirstitem(itemname)
If Not child.hasitem(itemname) Then
richStyle.Bold = True
Call rtitem.AppendStyle(richStyle)
Call rtitem.appendtext(itemname)
richStyle.Bold = False
Call rtitem.AppendStyle(richStyle)
Call rtitem.addnewline(1)
Call rtitem.appendtext(parentitem.text)
Call rtitem.addnewline(2)
End If
End Forall
'setting the third heading
richStyle.Underline = True
richStyle.Bold = True
Call rtitem.AppendStyle(richStyle)
Call rtitem.addnewline(2)
Call rtitem.appendtext("Items only on the Conflict Document")
richStyle.Underline = False
richStyle.Bold = False
Call rtitem.AppendStyle(richStyle)
Call rtitem.addnewline(2)
'Third test - all items on the child that aren't present on the parent
Forall j In child.items
itemname = j.name
Set childitem = child.getfirstitem(itemname)
If Not parent.hasitem(itemname) Then
richStyle.Bold = True
Call rtitem.AppendStyle(richStyle)
Call rtitem.appendtext(itemname)
richStyle.Bold = False
Call rtitem.AppendStyle(richStyle)
Call rtitem.addnewline(1)
Call rtitem.appendtext(childitem.text)
Call rtitem.addnewline(2)
End If
End Forall
report.sendto = session.username
report.subject = "Save Replication Conflict Report"
Call report.send(False)