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
jenvinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbonaciCommented:
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.
0
jenvinAuthor Commented:
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
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

jenvinAuthor Commented:
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
0
mbonaciCommented:
Use this class to implement document locking yourself (QueryOpen and QueryClose events):
http://chadsmiley.com/chadsmiley/2006/09/domino-document-locking-class-1-3/
0
jenvinAuthor Commented:
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?
0
jenvinAuthor Commented:
I am testing and this setting into read mode before closing also does not seem to be helping!
0
mbonaciCommented:
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?
0
jenvinAuthor Commented:
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?
0
mbonaciCommented:
Nowhere, just copy the code to the Declarations section and save the lib.
0
mbonaciCommented:
Do your users open that document manually or you open it for them in the background (e.g. using LotusScript)?
0
jenvinAuthor Commented:
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])
0
jenvinAuthor Commented:
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
0
mbonaciCommented:
You cannot call it like that, it's a class.
First let me ask you, have you tried to check the lock when closing document with formulas?
Something like this:

@If( !@IsNull( @DocLock( [STATUS] ) );
    @DocLock( [UNLOCK] );
    @Success )

Second, if you want to use LotusScript class you need to use it like this:


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

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jenvinAuthor Commented:
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!!!!

0
mbonaciCommented:
Great.
You did very good job modifying the code.
0
jenvinAuthor Commented:
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
0
jenvinAuthor Commented:
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
0
mbonaciCommented:
Try this:

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

I'm sorry, I currently don't have time for deeper analysis...
0
jenvinAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.