Replication-save-conflict problem

We have a database that has three agents that execute against documents ina specific view. We had tried to use the document locking for the

database, but had a problem with the document locking. Users would have

the document open, close the document and later, the document would than

state that the document was locked by that user who no longer had it open.

So we took off the document locking for the database.

Because these agents run every ten minutes, we have added the code to check

if the document is open, but something doesn’t seem to be working right.

Here is the code that we have within the body of the agent:

If doc.IsUIDocOpen Then

Else

Call doc.save(True, True)

End If

Anyone’s thoughts on how to fix the save-conflict error problem?

Thanks in advance for your help.

Jean

Subject: Replication-save-conflict problem

Use a profile document,

Whenever a user opens a document in EDIT mode add the NOTEID/UNID to this doc, delete the NOTEID/UNID in the doc close event if exists

Then agents will check against this doc to see if the NOTEID/UNID exists in this profile doc BEFORE processing the docs

VOILA

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.