Managing custom document locking to prevent conflict document

196 views Asked by At

I have a custom document process built into a ssjs object. When I click on the Edit button in a document in read mode, I call the method that sets a lock date/time and lock owner in the backend document and then returns true. Then the ChangeDocumentMode simple action can be used to change the document to edit mode. However, the first time I save the document (such as with a simple action), it creates a conflict document. It is likely that the frontend document is not aware of the backend document modification and save I did before going into edit mode.

If I change this process so that I let my document locking code set the two backend doc fields and then use context.redirectToPage, the document opens into edit mode and saving it from the ui does not create any conflict documents. However, if after using my code to unlock the document I use the Open Page simple action to go to "Previous Page" to exit the document, it goes only back to read mode instead of actually closing the document. I am sure that the initial redirectToPage disrupted the history and causes this problem.

The question: Does anyone have a suggestion on how I can lock the document before going into edit mode, go into edit mode, save without causing conflict documents, and still be able to exit using the Open Page simple action (after unlocking the document)?

Here is a sample of the relevant code for locking, including code to go into edit mode:

thisDoc.replaceItemValue("LockOwner",context.getUser().getCommonName());
thisDoc.replaceItemValue("LockDate",session.createDateTime(@Now()));
thisDoc.save();
var url = view.getPageName()+"?action=editDocument&documentId="+thisDoc.getNoteID();
context.redirectToPage(url);
1

There are 1 answers

1
stwissel On

It depends on your use case. If your application is the way users access the documents, I would recommend not to write anything into the documents for locking - you only end up with the need for an unlock admin function for users who disconnected (network, close browser, crash) before unlocking. The way locking is done e.g in WebDAV is a in-server-memory time lock that a call renews every 30 seconds. You would use a classic Ajax call for that.

The openNTF WebDAV for Domino project has the server side of such a locking mechanism, you might want to copy it from there.

In case you must write into the document: change the sequence and update the document in the queryOpen event in readmode - that covers the cases where a user had bookmarked the edit URL too.

Let us know how it goes!