Link to home
Start Free TrialLog in
Avatar of jenvin
jenvin

asked on

Lotus notes - Document Locking Feature Version 7 & 8

I am developing an application in Lotus Notes version 7 & 8. I want to use the document locking feature. I have seen that the inbuilt Lotus Notes feature of document locking does not work correctly. The documents are locked even when the user has closed the document. Is it better to code the document locking feature by having separate documents for each main document and track as soon as the document is locked by trapping the user name who is editing ? Is it possible to use the inbuilt locking feature using formulas such as @DocLock and make sure that every time the document is closed the document is unlocked for others to edit? My application does not have replicas. Even then the inbuilt locking does not work correctly
Avatar of mbonaci
mbonaci
Flag of Croatia image

When you say it doesn't work as expected, have you taken into account that:

 - you need to have Author access or higher to lock a document
 - you can place temporary lock by locking the doc manually, which stays active until the doc is unlocked manually (actions - lock document)
 - if you open the document in Edit mode you set a temporary lock that unlocks when you close the document
 - temporary locking is not supported on multiple replicas and only prevents two people from working in a document at the same time
 - you cannot access a locked document without the User ID that locked it
 - to unlock a document you have locked, you must use the same User ID you used when you locked the document and then select the document you want to unlock and either choose Actions - Unlock Document to manually unlock a document or simply close the document if you opened it in Edit mode to set a temporary lock
 - managers of a database cannot edit a locked document. However, managers can unlock documents that are locked

 - the Document.Lock method places a persistent lock if the administration (master lock) server is available or places a provisional lock if the administration server is not available and the second (lock provisional) parameter is true.
Avatar of jenvin
jenvin

ASKER

My Application does not have replicas so few of the concerns do not apply. My users will not like if I ask them to do a manual lock every time, before they open the document. This locking has to happen without the knowledge of the users. I have not done any programming when it comes to locking. I think the temporary lock that automatically comes up (I can see the $writers and the  $WritersDate) is the problem. Even after the document is closed these sometimes do not disappear and others cannot edit it
Avatar of jenvin

ASKER

These do not help. I cannot ask my users to manually  lock and unlock the documents before they open it Whatever solution we provide should not be visible to the user
Use this class to implement document locking yourself (QueryOpen and QueryClose events):
http://chadsmiley.com/chadsmiley/2006/09/domino-document-locking-class-1-3/
Avatar of jenvin

ASKER

ok I figured out the solution to overcome the soft locking issue of the $Writers and $WritersDate not disappearing after the document is closed
According to this technote

http://www-01.ibm.com/support/docview.wss?rs=0&q1=1100606&uid=swg21100606&loc=en_US&cs=utf-8&cc=us&lang=en
if we make sure that the document before closing is changed to read mode then the $Writers and $WritersDate disappears.

Should I also implement the document locking feature also apart from the soft locking that mbonaci has suggested ?
I am havng a problem doing that I added all the code "Domino Document Locking" into a script ibrary and called it "DominoDocumentLocking" When I tried to add the script library into the global options of the form Use "DominoDocumentLocking" i am not able to save the form.
Do i also have to add the code Public Sub new ( inDoc As Variant ) ......Public Sub RoleGroupOverRide ( RoleGroup As String )
 in the script library?
Avatar of jenvin

ASKER

I am testing and this setting into read mode before closing also does not seem to be helping!
If you solve temporary (soft) locking problem you don't need anything else.

About DominoDocumentLocking script library, all the code has to go to (Declarations) section.
Sub New is the constructor of the class, you don't need any additional subs outside the class.

Why aren't you able to save the form? Which error message appears?
Did you try with the new, empty script library and form?
Avatar of jenvin

ASKER

Changing the mode to read mode did not help remove the $Writers and $WritersDate fields It still exists in the document when I close it.

Where d I add the " Sub New" line?
Nowhere, just copy the code to the Declarations section and save the lib.
Do your users open that document manually or you open it for them in the background (e.g. using LotusScript)?
Avatar of jenvin

ASKER

They open it in the read mode and then whoever needs to edit they set it into the edit mode using a button (@Command[EditDocument])
Avatar of jenvin

ASKER

I have added "Use "DominoDocumentLocking"" in the Global Options of the form and in the querymode change I say "LockUIDocument(Source)" and it gives an error saying "Not a sub or function name : LockUIDocument
ASKER CERTIFIED SOLUTION
Avatar of mbonaci
mbonaci
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jenvin

ASKER

Hello mbonaci
When i use
@If( !@IsNull( @DocLock( [STATUS] ) );
    @DocLock( [UNLOCK] );
    @Success )
in the Queryclose event of the form I get an error "@Formulas cannot be used in this context"

In the querymodechange event I used

Sub Querymodechange(Source As Notesuidocument, Continue As Variant)
      If source.EditMode Then
            Dim locker As New DominoDocumentLocking( source )
            Call locker.LockUIDocument( source )
            
      End If
End Sub

and in the Queryclose event I used

Sub Queryclose(Source As Notesuidocument, Continue As Variant)
      If source.EditMode Then
            Dim locker As New DominoDocumentLocking( source )
            
            Call locker.UnLockUIDocument( source )          
      End If
End Sub

and IT SEEMS TO BE WORKING FINE!!!!!!

I will do some more testing and then confirm. You deserve 1000 points!!!!

Great.
You did very good job modifying the code.
Avatar of jenvin

ASKER

Thanks for the prompt help mbonaci. The application is not yet in production. If i need help on the locking feature when this application goes into production will take your help
Avatar of jenvin

ASKER

Hello mbonaci

I added the following code in the querymode change

Sub Querymodechange(Source As Notesuidocument, Continue As Variant)
      If source.EditMode Then
            Dim locker As New DominoDocumentLocking( source )
            Call locker.LockUIDocument( source )
           
      End If
End Sub

When one document is locked by a user and another user tries to edit the same document the code works fine.

When the same user opens two instances of the same document then it allows both the instances of the document to get into the edit mode and then when you save the documents there is a replication conflict

I have tried checking using the following code in the query open

      Dim locker As New DominoDocumentLocking( source )
      Dim islocked As Boolean
      islocked =locker.IsUIDocumentLockedByCurrentUser ( Source)
            If islocked = True Then
            
            Msgbox "Another copy of this document is already open"
            Continue = False
            
      End If      

this works in the query open but not in the Querymodechange it returns True in both the cases and I cannot check if it is the first instance that is being sent into the edit mode

Please suggest what i need to do
Try this:

islocked = locker.IsUIDocumentLockedByCurrentUser( Source ) Or locker.IsDocumentLockedByCurrentUser( Source.Document )

I'm sorry, I currently don't have time for deeper analysis...
Avatar of jenvin

ASKER

ok Have found a solution for the problem.

I am assumng the user opens the two instances of the same document in the same machine
I am preventing the user from opening two instances of the same document by using environment variables for each document using the document id

In the queryopen event i say

      If Not Source.Document.IsNewNote Then
            Dim session As New NotesSession
            Dim latestNumber As String            
            latestNumber = session.GetEnvironmentString(source.Document.UniversalID)            
            If latestNumber ="" Then                  
                  Call session.SetEnvironmentVar( Cstr(source.Document.UniversalID), Cstr(source.Document.UniversalID) )
            Else
                  Msgbox "Another instance of this document is already open "
                  Continue = False
            End If            
      End If


In the Queryclose

If Not Source.IsNewDoc Then
            Dim session As New NotesSession
            
            Call session.SetEnvironmentVar( source.Document.UniversalID, "" )
            
            If source.EditMode Then
                  Dim locker As New DominoDocumentLocking( source )
                  
                  If locker.IsDocumentLocked ( Source.document) = True Then
                        Call locker.UnLockUIDocument( source )          
                  End If
                  
            End If
      End If

the unlock code is also present