Obsolete - Domino has document locking as a built-in feature. Use new new development.
---------------------------------------------------------------
COOL DOMINO PROGRAMMING TIP
---------------------------------------------------------------
Title: Record Locking Made Simple
Author: Yvonne Ewing, Independent
This is a method I came up with to "lock" a record by
a user when editing. Other information I found either
had me using several complicated scripts that weren't
working for us (due to restricted agents) or called for
a save on the close event. The save on the close event
forces changes to be saved even if the user didn't want
them saved.
The code causes a message to be produced if other users
try to edit the document while someone is already doing
so. It indicates who has the document locked which
should help track down the user if there are questions
about leaving a document open unintentionally.
I created a hidden view called (DocLock) with the alias
of DocLock to use for the lookup (getdocumentbykey
method).
I then created a form also called DocLock with the fields:
DocLock (to store the unid of the document to be locked)
and CreatedBy (to hold the name of the author).
I then placed this code in the QueryModeChange event
and the QueryModeClose event.
Code for the QueryModeChange Event
----------------------------------------
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim ws As NotesUIWorkspace
Dim newdoc As NotesUIDocument
Dim doc As NotesDocument
Dim destnote As NotesDocument
Dim destview As NotesView
Set db = sess.CurrentDatabase
Set ws = New NotesUIWorkspace
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
unid$ = doc.UniversalID
Set destview = db.GetView("DocLock")
Set destnote = destview.GetDocumentByKey(unid$,
True)
If destnote Is Nothing Then 'Document is
not being edited by another user.
Set lockdoc = New NotesDocument( db )
lockdoc.Form = "DocLock"
lockdoc.DocLock = unid$
lockdoc.CreatedBy = sess.CommonUserName
lockdoc.Save True, False
Else 'The document is already being edited by
another user.
lockedBy = destnote.GetItemValue("CreatedBy")
Messagebox "Document cannot be edited."_
& Chr$ (10) & Chr$ (10) & "This document is
currently being edited by: " + lockedBy(0) _
& Chr$ (10) & Chr$ (10) & "You may only
view the document." _
& Chr$ (10) & Chr$ (10) & "Please try to
edit the document again later.", _
MB_OK+MBIconExclamation, "Cannot Edit"
Continue = False
Exit Sub
End If
Code for the QueryClose Event
-----------------------------------------
Dim sess As New NotesSession
Dim ws As NotesUIWorkSpace
Dim db As NotesDatabase
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim destnote As NotesDocument
Dim destview As NotesView
Set ws = New NotesUIWorkSpace
Set uidoc = ws.currentdocument
Continue = True
Set db = sess.CurrentDatabase
Set doc = uidoc.Document
unid$ = doc.UniversalID
Set destview = db.GetView("DocLock")
Set destnote = destview.GetDocumentByKey(unid$,
True)
If destnote Is Nothing Then 'Document is not
locked. Users shouldn't be able to get here.
Exit Sub
Else'Document is locked, need to unlock.
destnote.Remove (True)
End If
previous page
|