Subject: Replication-save-conflict problem
I’m embarrased to admit, for an application when I had a similar problem (ran every 15 minutes) I developed my own locking process.
It worked in conjuction with the fact I wanted to track field changes and made it so the user could control what fields were tracked.
Whenever, a document is opened (even in read mode) I create a Copy of that document (current status). When the document is closed I then remove that Copy Document (after doing a check to see if any key fields are changed and log those).
Therefore, I just added to that process to state if an Original Copy document exist then the document is open by someone (including an agent) and locked.
So my Query Open looks like:
Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
If Not source.IsNewDoc Then
If IsTheDocLocked ( source.Document, True ) Then
Msgbox "Unable to open document as it is locked by " + TheDocLockedBy( source.Document, "Abbreviated") + ". Please try again later.", 0+64, "FYI"
Continue = False
Exit Sub
Else
Call CreateOrgCopyDoc ( source.document )
End If
End If
End Sub
Thisi is the Function IsTheDocLocked. It also talks about “To Do” documents as I had a virtual parent child relationship and therefore a change made on a parent needed to be applied to the child document which could be “locked” so I create a To Do Document until that change goes in place.
Public Function IsTheDocLocked( doc As NotesDocument , IncludeToDoDocs As Boolean) As Boolean
' Note there is a routine call IsDocLocked in the AttachmentLib
Dim s As New NotesSession
Dim thisdb As NotesDatabase
Dim luview As NotesView
Dim luDC As NotesDocumentCollection
Dim key As String
Dim result As Boolean
result = True ' Assume the Document is Locked
key = doc.UniversalID
Set thisDB = s.CurrentDatabase
' Check to see if there is a OrgCopyDoc, if there is then the Document is locked
' * if the view is nothing we then assume the document is locked for protection
Set luView = thisDB.GetView( luOrgCopyDoc$ )
If Not luView Is Nothing Then
Set luDC = luView.GetAllDocumentsByKey( key, True )
If luDC.Count = 0 Then
result = False
End If
End If
' If there are NO OrgCopyDo then Check to see if there are any ToDoDocs,
' If there are ToDo Docs then the Document is locked
' * if the view is nothing then we assume the document is locked for protection
If IncludeToDoDocs Then
If Not result Then
Set luView = thisDB.GetView( LookUpOutstandingDocsView$ )
If Not luView Is Nothing Then
Set luDC = luView.GetAllDocumentsByKey( key, True )
If luDC.Count > 0 Then
result = True
End If
Else
result = True ' No view - then return Document is locked
End If
End If
End If
IsTheDocLocked = result
End Function
Similarly in the agent that runs as I work through the document collection like the Query Open I have:
While Not doc Is Nothing
If Not IsTheDocLocked( doc, True ) Then
Call CreateOrgCopyDoc ( doc )
...
Finally in the Query Close / Agent end after finished with the document:
RemoveOrgCopyDoc( Source.Document.ActionDetDocID(0) )
That’s how I handled things. Since adding that, I’ve no longer had replication / save conflicts but I’ve also blocked people from creating Local replicas which my code won’t overcome.