Search This Blog

Saturday, August 31, 2013

Both documents become replication or save conflicts

Hi guys

Recently working on one application I noticed that when two users edit the same document in the same time and both users save their changes then you get TWO replication conflicts, instead of one regular document and one replication or save conflict.

That was quite unexpected behavior and though I found out the reason I still do not understand WHY it works like it works. Probably you may tell me...


So let's check a simple scenario of getting replication or save conflict:

1) Create a new database or use existing one
2) Get one simple form, one view and make an agent that does something like Field a := @now;
3) Create a new document, save it but do not close it
4) Switch to the view and run agent on the document you keep opened in another tab
5) Switch back to the open document and press Ctrl+S.
6) Say YES when Notes will ask you if you want to save your document as a replication or save conflict.

Now you have something like this and this is exactly what you may expect


Now let's see what happens if you add call Source.Document.Save(true, false) into the PostSave even of your form.

Do all those steps again and check what you get this time.
In my case (IBM Lotus Notes 8.5.3 FP2) I got this result:


Can you explain that? I cannot :-)
-----------------------
15.07.2021 Updated

Just got this problem again. 
I noticed that the document which had to stay normal but which also became a conflict was referred to itself, I mean that one of this conflict document had $REF the same as its UniversalID so I wrote a simple workaround. Add this block of code after doc.save() in PostSave - it can fix the problem in some cases. I say in some cases because it is possible that parentDoc could be also open by someone in edit mode and then another conflict should be created after the block below cleans the $REF and $Conflict.

Dim db As notesdatabase
Dim parentDoc As notesdocument
Set db = Source.Document.ParentDatabase
If Source.Document.HasItem("$Conflict") And Source.Document.ParentDocumentUNID <> "" Then
Set parentDoc = db.GetDocumentByUNID(Source.Document.ParentDocumentUNID)
If Not parentDoc Is Nothing Then
If parentDoc.HasItem("$Conflict") And parentDoc.UniversalID = parentDoc.ParentDocumentUNID Then
Call parentDoc.RemoveItem("$Conflict")
Call parentDoc.RemoveItem("$REF")
Call parentDoc.save(True, False)
End If
End If
End If





1 comment:

  1. Oh yes, this is so true! but I cannot explain and do not have a workaround. (I know this post is old)

    ReplyDelete