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 ''
Es ist der Name des Item ("Lock"). In R5 hatte dieses Item noch keinerlei (System-)Bedeutung, jetzt ist es ein reservierter Name für das in R6 integrierte Document locking.
Bernhard
- kopiere das Script in die Script-Options von Feld Gesperrt
- Der debugger läuft ohne zu Murren durch aber trotzdem bekomme ich keine Meldung das ein Dokument schon bearbeitet wird usw.
varLock=docBackend.GetItemValue("Gesperrt") ' <-----
If (varGesperrt(0) <> "") Then '<------
Msgbox ("Document is currently locked by "+varLock(0)+". A read-only copy will be opened for your use.")
Exit Sub
End If
Das ganze Script in den Speicher und dann in die Options vom Feld Gesperrt