?
Solved

r5 document locking code solutions for R 5.0.12     ( ghassan )

Posted on 2006-04-25
6
Medium Priority
?
297 Views
Last Modified: 2013-12-18
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.
0
Comment
Question by:BroadAustralia
  • 2
  • 2
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
marilyng earned 2000 total points
ID: 16540203
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
 

Expert Comment

by:gghaleb
ID: 16542124
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
 
LVL 1

Author Comment

by:BroadAustralia
ID: 16542515
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 

Expert Comment

by:gghaleb
ID: 16544732
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
 
LVL 1

Author Comment

by:BroadAustralia
ID: 16548980
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
 
LVL 18

Expert Comment

by:marilyng
ID: 16549303
Broad, thanks for the points!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…
Suggested Courses
Course of the Month5 days, 13 hours left to enroll

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question