Link to home
Start Free TrialLog in
Avatar of toblo
toblo

asked on

'Locking' documents?

Hi!

I'm using a document in the DB to store a number that might get changed.

My problem is that I wan't to be sure that noone else is making changes in the same document at the same time..

Is there any way to 'lock' documents, or see if anyone else are editing them at the same time?

Regards
/Torbjörn Josefsson
ASKER CERTIFIED SOLUTION
Avatar of HemanthaKumar
HemanthaKumar

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

ASKER


Cool :)
Sounds very workable!

Thanks
/Torbjörn Josefsson
Here is a little Script to prevent 2 users from editing the same document.  

First create a hidden field on your Form- Text-Editable called Flag1 with a default of "Unlocked".

In Script in the QueryOpen event:

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
     Dim session As New notessession
     Dim db As notesdatabase
     Dim doc As notesdocument
     Dim item As notesitem
     Dim array(1) As String
     Set db=session.currentdatabase
     
     Set doc=source.document
     
     If Not Isnewdoc Then
          If doc.hasitem("Flag1") Then
               Set item=doc.getfirstitem("Flag1")
               array(0)=item.values(0)
               If array(0)="Locked" Then
                    Msgbox "Someone Else is Editing this Document. Please Try Again Later.", 64, "Document is Being Edited"
                    continue=False
               Else
                    continue=True
                    array(0)="Locked"
                    item.values=array(0)
                    Call doc.save(True,True)
               End If
          End If
     End If
End Sub

Then in the QueryClose event:

Sub Queryclose(Source As Notesuidocument, Continue As Variant)
     Dim session As New notessession
     Dim db As notesdatabase
     Dim doc As notesdocument
     Dim item As notesitem
     Dim array(1) As String
     Set db=session.currentdatabase
     Set doc=source.document
     Set item=doc.getfirstitem("Flag1")
     continue=True
     array(0)="Unlocked"
     item.values=array(0)
     Call doc.save(True,True)
End Sub