'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
tobloAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
HemanthaKumarConnect With a Mentor Commented:
You can use the authors field to accomplish this task.

Use Authors field and store the current username and save the document ( In Postopend event). So that if any user opens the document he can see the data but cannot edit one.

After first user completes the operation and exits, reset the author field to null, so that other person can edit in future.

Good Luck
Hemanth
0
 
tobloAuthor Commented:

Cool :)
Sounds very workable!

Thanks
/Torbjörn Josefsson
0
 
tomrodCommented:
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
0
All Courses

From novice to tech pro — start learning today.