I get a save conflict when using doc.save(false, false)

Hello,

I’ve got a background agent that gathers all the documents for which the boolean field “was_sent” is “No”, sets it to “Yes” and sends a mail automatically to the right person (actually, it’s a bit more complicated but let’s keep it simple).

Now, if the document is being edited at the time the agent processes this document, I don’t want this document to be saved.

So I use notesDocument.save(false, false) which is supposed to cancel the save.

But I still get a save conflict. Did I misunderstand the save(false, false) thing?

Subject: I get a save conflict when using doc.save(false, false)

It’s not your agent that’s creating the duplicate, it’s the user who’s editing it.
e.g. 1

Your agent gets a NotesDocument

A user opens the same document

The user saves the document

Your agent’s Save(False,False) will fail, because the document was modified after it got the document.

e.g. 2

Your agent gets a NotesDocument

A user opens the same document

Your agent’s Save(False,False) will succeed, because the document was not modified after it got the document.

The user saves the document, and will be warned that it’s going to cause a conflict. If they say YES, then a conflict document is created.

e.g. 3 [This is the one that’s most likelly causeing you trouble]

A user opens the same document

Your agent gets a NotesDocument

Your agent’s Save(False,False) will succeed, because the document was not modified after it got the document.

The user saves the document, and will be warned that it’s going to cause a conflict. If they say YES, then a conflict document is created.

Look into Document Locking which should prevent a 2nd opening/editing of a document.

Subject: RE: I get a save conflict when using doc.save(false, false)

Would document locking work in the following case:

  • Your agent gets a NotesDocument

  • A user opens the same document in read mode

  • Your agent’s Save(False,False) will succeed, because the document was not modified after it got the document.

  • The user goes into edit mode and saves the document, and will be warned that it’s going to cause a conflict. If they say YES, then a conflict document is created.

Subject: RE: I get a save conflict when using doc.save(false, false)

Unfortunately, document locking is the only robust way of dealing with such a problem.

Document locking works across replicas on servers connected to each other, so it’s a very useful and powerful tool, but requires some coding to get to work.

It was the only thing able to allow me to build an almost fool-proof system to build unique document number identifiers in an application I wrote about 6 months ago. (There’s even a lockHolders property available in the NotesDocument class)

But even that isn’t perfect, but the users are aware of the potential problems which, in 6 months have not arisen.

Subject: RE: I get a save conflict when using doc.save(false, false)

ok thanks to both of youI’ll dig into the document locking

Subject: I get a save conflict when using doc.save(false, false)

.save(false,false) only cancels the save if someone else is editing the document on the same replica at the same time.