'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?
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.

HemanthaKumarCommented:
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

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