r5 document locking code solutions for R 5.0.12 ( ghassan )

Hi EE,

Have got this code from an existing application that was used to enable document locking for R5 apps.  Ghassan I hope this helps you?

Marko re: your comment in previous EE Q. I guess this snippet does require delete access in ACL  ( I'm just trying to understand ,oh, and suck your brains ;)  ):
If lockdoc.form(0)="Lock" Then            'Remove if response is a lock doc
Call lockdoc.remove(True)

** Just checked ACL all users who typically worked with this form did have delete document access... So I guess while this works, its not ideal..


QueryOpen:
---------
'PURPOSE: Looks for lock documents to see if the person can enter the file - otherwise lets them in and
'creates a new lock document

Sub Querymodechange(Source As Notesuidocument, Continue As Variant)
      Dim session As New notessession
      Dim db As notesdatabase
      Set db =session.currentdatabase
      Dim doc As notesdocument
      Dim checkdoc As notesdocument
      Dim lockdoc As notesdocument
      Dim item As notesitem
      Set doc=source.document
      Dim collection As notesdocumentcollection
      Dim lockname As String
      Dim i As Integer
      If source.editmode=False Then
            Set collection= doc.responses
            If collection.count>0 Then
                  i=1
                  While i<=collection.count
                        Set checkdoc=collection.getnthdocument(i)
                        If checkdoc.form(0)="Lock" Then
                              lockname=checkdoc.lockedby(0)
                        End If
                        i=i+1
                  Wend
            End If
            If lockname<>"" Then
                  Messagebox "This file is currently being edited by "+lockname
                  continue=False
            Else
            'Create new lock document
                  Set lockdoc=db.createdocument
                  lockdoc.form="Lock"
                  lockdoc.lockedby=session.commonusername
                  lockdoc.docauthor= session.username
                  Set item=lockdoc.getfirstitem("DocAuthor")
                  item.isauthors=True
                  Call lockdoc.makeresponse(doc)
                  Call lockdoc.save(True,False)      
            End If
      End If
End Sub
---------

QueryModeChange:
----------
'PURPOSE: Looks for lock documents to see if the person can enter the file - otherwise lets them in and
'creates a new lock document

Sub Querymodechange(Source As Notesuidocument, Continue As Variant)
      Dim session As New notessession
      Dim db As notesdatabase
      Set db =session.currentdatabase
      Dim doc As notesdocument
      Dim checkdoc As notesdocument
      Dim lockdoc As notesdocument
      Dim item As notesitem
      Set doc=source.document
      Dim collection As notesdocumentcollection
      Dim lockname As String
      Dim i As Integer
      If source.editmode=False Then
            Set collection= doc.responses
            If collection.count>0 Then
                  i=1
                  While i<=collection.count
                        Set checkdoc=collection.getnthdocument(i)
                        If checkdoc.form(0)="Lock" Then
                              lockname=checkdoc.lockedby(0)
                        End If
                        i=i+1
                  Wend
            End If
            If lockname<>"" Then
                  Messagebox "This file is currently being edited by "+lockname
                  continue=False
            Else
            'Create new lock document
                  Set lockdoc=db.createdocument
                  lockdoc.form="Lock"
                  lockdoc.lockedby=session.commonusername
                  lockdoc.docauthor= session.username
                  Set item=lockdoc.getfirstitem("DocAuthor")
                  item.isauthors=True
                  Call lockdoc.makeresponse(doc)
                  Call lockdoc.save(True,False)      
            End If
      End If
End Sub
------------

QueryClose:
-------------
'PURPOSE: If a user is in edit mode, any responses that are record lock documents are removed when
'closing the document

Sub Queryclose(Source As Notesuidocument, Continue As Variant)
      Dim session As New notessession
      Dim db As notesdatabase
      Set db=session.currentdatabase
      Dim collection As notesdocumentcollection
      Dim doc As notesdocument
      Dim lockdoc As notesdocument
      Dim i As Integer
      i=1
      Set doc=source.document
      If source.editmode Then
            Set collection=doc.responses
            While i<=collection.count
                  Set lockdoc=collection.getnthdocument(i)
                  If lockdoc.form(0)="Lock" Then            'Remove if response is a lock doc
                        Call lockdoc.remove(True)
                  End If
                  i=i+1
            Wend
      End If
End Sub
-------------

New Form:
Name: Lock    FormType: Response
Elements:
FIELD1:  DocAuthor  /  Authors  /  ComputerWhenComposed  /  DefaultValue:  @Username
FIELD2: LockedBy /  Text  /  Editable

New View:
Name: Lock
View Selection: SELECT form="Lock"
Columns
COL1: form
COL2: lockedby
-------------------------

EE, any appraisal on this code?  I am not the author but would be interested in thoughts / comments as I'm just learning Notes Dev.?

Broad.
LVL 1
BroadAustraliaAsked:
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.

marilyngCommented:
Interesting use of response documents, but had too many orphaned documents experiences.  But, biggest problem is that you can end up with several lock documents with several different authors, and if replicated, the lock docs replicate but the command to remove might not.

So-

Lockdoc is separate document
authors field = */O=thisdomain
lockdoc gets docunid, username, servername, lockdate locktime
deleteme field = ""

view for lockdoc by documentunid
where deleteme<>"" and lockdate is not older than 24 hours.

postopen and postmodechange events check for existance of lock doc is form is going into edit mode.
then your code is OK.. check for docid, if it's there then display message, else create the lockdoc.

Now, whenever you go to close the document, you should check for and remove all instances of lockdoc, in this case all you have to do is grab the collection and set deleteme  = "deleteme"

Cleanup agent to delete documents where deleteme <>"" and lockdate is over 1 day old.

Replication formula to not replicate lockdocs.

------------
The idea that you have to create a document in order to lock is correct.

The postopen and postmodechange
  basically check to see if doc is going to edit mode or is in edit mode.  
  if it's a new doc, then forget it... let it open
  if not then do a dblookup for the document unique, if found then display the message, and allow the document to open in READ mode.
  if not found, then create the lock document and allow the form to open in edit mode.
 

Also, good that the code uses the query close event to remove the lock document.

---------------






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
gghalebCommented:
Cool...I would like to absolutely have one replica of the this database. is it possible to prevent ANY replication?
Also, to be honest I have not looked into the code in great detail, but does this require "document Locking" to be enabled or the use of response documents does not require this.
This is because when I enable "Document Locking" it asks for an Admin locking server? is this necessary.

I like the idea of getting response documents saying "user X is editing", I will be looking at the code in more details.
0
BroadAustraliaAuthor Commented:
Hi Ghassan,

Not sure what u mean in your first sentence?

If your using r6 use the native document locking the product shipped with.

If your using r5 u can use the above ( check out Marliyn post though -- there are mods that def. should be made ).    The down side though is the users require delete access in acl...

Broad.

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

gghalebCommented:
Hi,

Thanks Broad,
I am planning to create a database application which is "light"....not alot of data (but very useful.)
I will put this .nsf on a domino server online, but I want to prevent anyone from replicating it locally or anywhere else.
I want to disable the ability of any replication on this database. is this possible?

Also I am using r6, so there is document locking. However, it asks for an admin locking server to be specified. What is that?
Also, when using the native document locking feature, can you get a message saying who is currently updating a certain document?

Regards,

-- sorry I am new to Lotus Notes + Domino

0
BroadAustraliaAuthor Commented:
Hi Ghassan you will have to raise new questions for your queries.  Firstly however, search thru the EE knowledge base as I would suggest most of your queries have been answered in existing posts.

Broad.
0
marilyngCommented:
Broad, thanks for the points!
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.