Resolving Replication Conflicts (R4.X)

The following script finds replication conflicts by looking for $Conflict, and
then resolves the conflict by promoting the loser of the conflict to be the
winner.
(To increase the performance of this code, use the GetNextDocument method
instead of GetNthDocument.)
Dim s As New notessession
Dim db As notesdatabase
Dim col As notesdocumentcollection
Dim doc As notesdocument
Dim parent As notesdocument

Set db=s.CurrentDatabase
Set col=db.UnprocessedDocuments

If col.Count > 0 Then
For i=1 To col.Count
Set doc=col.GetNthDocument(i)

'Check to see if the selected document is a conflict response
If doc.HasItem("$Conflict") Then

docId$=doc.UniversalId
parentId$=doc.GetItemValue("$REF")(0)
'Promote the loser to a document
Call doc.RemoveItem("$Ref")
Call doc.RemoveItem("$Conflict")

'Get original winner
Set parent=db.GetDocumentByUnid(parentId$)
If Not parent Is Nothing Then

'Remove original winner
Call parent.Remove(True)
End If

'Reset the DocumentUniqueID, responses are still pointing to correct document,
and replication is done on the correct document
doc.UniversalId=parentId$
Call doc.Save(True, True)

'Somehow instead of overwriting the ID, a copy is created so it is necessary to
delete the original loser
Set doc=db.GetDocumentByUNID(docId$)
If Not doc Is Nothing Then
Call doc.Remove(True)
End If
End If
Next
End If

This was first published in November 2000

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.