Link to home
Start Free TrialLog in
Avatar of BroadAustralia
BroadAustraliaFlag for Australia

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of marilyng
marilyng

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 gghaleb
gghaleb

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.
Avatar of BroadAustralia

ASKER

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.

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

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