Manage Learn to apply best practices and optimize your operations.

Locking documents to prevent save conflicts

Locking documents to prevent save conflicts

This piece of code assigns edit lock to the first user who opens the document. When other users try to open the same document, they get a message saying "Document is locked by X" and a read-only copy is opened for them. They will not be able to edit the document until the lock is released by the first user.

A manually run agent to unlock the document can be provided for Domino Admin in case of system crash.


Form should have a hidden field called "Lock" of type Text (Editable)

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
	If (Source.IsNewDoc) Then
		Exit Sub
	End If   'New Doc, Lock not reqd
	Dim varLock As Variant
	Dim session As New NotesSession
	Dim nnUserName As New NotesName(session.UserName)
	Set docBackend=Source.document
	varLock=docBackend.GetItemValue("Lock")
	If (varLock(0) <> "") Then
		Msgbox ("Document is currently locked by "+varLock(0)+". A read-only copy will be opened for your use.")
		Exit Sub
	End If
	docBackend.Lock=nnUserName.Common
	Call docBackend.Save(True,True)
End Sub

'When user trys to edit, check if he/she has the lock

Sub Querymodechange(Source As Notesuidocument, Continue As Variant)
	If Source.FieldGetText("Lock")<>"" Then
		Dim session As New NotesSession
		Dim nnUserName As New NotesName(session.UserName)
		If (Strcomp(nnUserName.Common,Source.FieldGetText("Lock"),5)=0) Then
			continue=True
		Else
			Msgbox("Sorry, you are in read-only mode ! This operation cannot be performed. This document is currently used by "+Source.FieldGetText("Lock"))
			continue=False
		End If
	End If
End Sub

'Release the lock when the user with the lock closes the document

Sub Queryclose(Source As Notesuidocument, Continue As Variant)
	If strNewDoc="New" Then  '(exit if it's a new doc.Set this variable to New in postopen if it's a new doc)
		Exit Sub
	End If
	
	Dim session As New NotesSession
	Dim nnUserName As New NotesName(session.UserName)
	If (Strcomp(nnUserName.Common,Source.FieldGetText("Lock"),5)=0) Then
		Set docBackend=Source.document
		docBackend.Lock=""
		Call docBackend.Save(True, True)
	End If
	
End Sub

Agent to Unlock selected documents -
Manually run agent - Simple Action
Modify field 'Lock': Set to ''

Dig Deeper on Domino Resources - Part 4

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close