Recently I’ve attempted to enable document locking in a database. The following happens:
The user creates a new document by pressing a button from a view,
Press a button which imports certain fields from another database, including Rich Text fields.
This button has Lotusscript in it and after fields get loaded it closes the front end and reopens it in edit mode so that the Rich Text content appears.
Call uidoc.Save
Call uidoc.Close()
Call doc.Save(True,True)
Set uidoc2 = ws.EditDocument(False,doc)
uidoc2.EditMode = True
On the Status bar the message that appears after the above steps are performed is “Document Successfully Unlocked”!!
If I press Save the message to save as a Save Conflict appears where it shouldn’t because the user wants to continue editing the document.
Through certain print messages in the code I’ve discovered that the QueryClose event runs as the last thing when the button is pressed.
My question is how can i make the document to remain locked and prevent it from unlocking?
I haven’t done this in a database with document locking enabled, but you don’t have to save the document to update Rich Text fields:
doc.SaveOptions = “0”
Call uidoc.Close
Set uidoc2 = ws.EditDocument(True, doc, , , , True)
Delete uidoc
Call doc.RemoveItem(“SaveOptions”)
If you do want to save the document, you don’t have to call both uidoc.save and doc.save:
Dim noteid As String
Call uidoc.Save
noteid = doc.NoteID
Call uidoc.Close(True)
Set doc = db.GetDocumentByID(noteid)
Set uidoc = ws.EditDocument(True, doc)
When you use uidoc.Close(True) it destroys any references to the NotesDocument that was contained in the NotesUIDocument. You have to retrieve it from the database and the NoteID is the easiest way to get to it.
First I have to disagree with Charles about “you don’t have to call both uidoc.save and doc.save” because if you have a document open in edit mode and make changes to it in the backend through LotusScript, you do need to save both the backend and the frontend to avoid losing the changes.
But having said that I want to thank Charles because his suggestion pointed me in the right direction when I ran into a similar problem to Mariam.
If you change the code from this:
Call uidoc.Save
Call uidoc.Close()
Call doc.Save(True,True)
Set uidoc2 = ws.EditDocument(False,doc)
uidoc2.EditMode = True
To this it will work with document locking (at least it did for me):
Call uidoc.Save
’ Save the backend document
Call doc.Save(True, True)
’ Get the Note ID for the current document so that it can be opened again
Dim noteid As String
noteid = doc.NoteID
’ set the save options to zero (this prevents the warning about saving changes) and then close the document
doc.SaveOptions = “0”
Call uidoc.Close(True)
’ then grab the document in the backend and reopen it
I’m glad you were able to use my suggestion. I usually only force the document to save as part of a close routine, and in that case just saving the uidoc is enough. I guess if you were doing something else you might have to save both the uidoc and the backend doc. That’s not something I’ve ever done so I’m not sure what the exact use case is for that. Thanks for making me aware that it is sometimes necessary, at least now I know to be on the lookout in case I do have forced saves go wonky.