Pages

Wednesday, January 20, 2010

Locking Lotus Notes Document Programatically Using Lotusscript - A version independent solution

'define a Script Library with the 'following specifications

'@Name  :  locktest
'@Usage :  Necessary elements to Programatically lock a document irrespective of the version of lotus notes

'(Declarations)
'****************
Dim lockstatus As String
Dim username As NotesName
Dim flag As Boolean


'a function isbeingused()
'**************************
Function Isbeingused(source As NotesUIDocument)
   
    On Error Goto erh
   
    If source Is Nothing Then
        Msgbox "the current document handle is not set  - script library  ""locktest""",,"Exiting"
        Exit Function
    End If
    If source.IsNewDoc Then
        Exit Function
    Else
        'Msgbox  source.FieldGetText("lockingfield")
        If source.EditMode=True Then
            If lockstatus<>"" Then
                Msgbox lockstatus
                Exit Function           
            Else
               
                lockstatus = "The document is in use by "+username.Canonical+Chr(13)+  _
                "So please try again after some time"
            End If
        End If
    End If       
    Exit Function
erh:
    Msgbox "Error in script library ""locktest""" & Chr(13)  _
    & Cstr(Erl)+" "+ Error
    Exit Function
End Function



'a garbageCollector gc()
'*****************************
Function gc()
    lockstatus=""
End Function



'A function isDocumentAlreadyOpen()
'*****************************
Function isDocumentAlreadyOpen(uidoc As NotesUIDocument) As Boolean
    If lockstatus<>"" Then
        Msgbox lockstatus,,"exiting"
       
        isDocumentAlreadyOpen =False
    Else
        isDocumentAlreadyOpen=True
    End If
   
End Function


'*********************************************************
' place the following code in a form (the document source)
'*********************************************************


'(options)
**********
Use "locktest"


'(Queryopen) event
******************
Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
    On Error Goto erh
    Call Isbeingused(Source)
    Exit Sub
erh:
    Msgbox "Error in queryopen event on form ""locktest""" & Chr(13)  _
    &  Error +" on line "+Cstr(Erl)
    continue=False
    Exit Sub
   
End Sub

'(Querymodechange) event
'************************
Sub Querymodechange(Source As Notesuidocument, Continue As Variant)
    If Not( isDocumentAlreadyOpen(source)) Then
        continue=False
        Exit Sub
    End If
End Sub

'(Queryclose) event
'*********************
Sub Queryclose(Source As Notesuidocument, Continue As Variant)
' nullify the locking field to allow others to access the document once u close it
    Call gc()
End Sub

1 comment:

  1. Hi Sir,
    I have a problem on xPage that How to upload a photo in xPage document and How to see it on both edit and read mode...?

    ReplyDelete