Pages

Wednesday, January 20, 2010

Lotusscript code fragment that shall act like a on-off switch on notes documents

%Rem
    @Created 1/28/2008
    @Author  Karthikeyan.A
    @Purpose This must be included into the application being built inorder to achieve a better command over the various functionalities
    @syntax enableOrDisable(status as boolean,fieldname as string,ActiveState as string, InactiveState as string)
    @Scope: Must be put in a Script Library to achieve a global scope

Explanation: 
    (1) You must have a view indexed by the various functionality in the database
    (2) The document contained in the view must contain field,say "ActivityStatus" dedicated to hold the status information of the concerned functionality
    (3) The contents of the field must be either 0 or 1
    (4) 0-indicates that the function is disabled and 1- intdicates the function is active
    (5) Parameters
        Status- False or True
        FieldName- The name of the field that holds the status value(here it is "ActivityStatus")
        ActiveState- string that represents the active state in the field (here it is the content of "ActivityStatus")
        InactiveState- string that represents the inactive state in the field (here it is the content of "ActivityStatus")
   
%End Rem

'Declarations
'**************

Dim fieldname As String
Dim functionalitystatus As Boolean

Dim temp As String
Dim session As NotesSession

Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument

Dim ActiveState As String
Dim inactiveState As String

'code of the Function
'**********************
Function enableOrDisable(functionalitystatus,fieldname,ActiveState,InactiveState)
    On Error Goto errHandler   
'*********************
   
    'change the status code as per your specification
    'Active=1 or "active" or"ur choice"
    'Inactive=0 or "inactive" or "ur choice"
   
'**********************
'check if the parameter passed are valid inputs and if not prompt the user and exit   
    If Trim(functionalitystatus)="" Or Trim(fieldname)="" Then
        Msgbox "Please provide both the parameters for the function enableOrDisable(status,fieldname)",,"Exiting..."
        Exit Function
    End If
'if the status is true then assign 1 to temp or if its false assign 0 else prompt the user to give a valid input and exit
    If functionalitystatus=True Then
   
        temp=ActiveState
    Else
        If functionalitystatus=False Then
   
            temp=InactiveState
        Else
            Msgbox "Invalid type of argument""" & functionalitystatus & """",,"Exiting"
            Exit Function           
        End If
    End If
        'handle errors in case of abrupt termination
   
        'set the current session
    Set session = New NotesSession
        'set the current database
    Set db=session.CurrentDatabase
'        if in case the database is not open prompt the user and exit
    If Not db.IsOpen Then
        Msgbox "The handle for the current database is not set",,"Exiting..."
        Exit Function
    End If
'get the handle of all the selected documents   
    Set dc=db.UnprocessedDocuments
'if in case no documents are selected prompt the user and exit    
    If dc.Count=0 Then
        Msgbox "no documents selected"       
        Exit Function
    End If
    'get the handle of the first document in the collection
    Set doc=dc.GetFirstDocument
    'if the document is nothing then prompt the user and exit
    If doc Is Nothing Then
        Msgbox "doc not set"
        Exit Function
    End If
    'loop through the collection of documents and assign them with the required status information
    While Not(doc Is Nothing)
        Call doc.ReplaceItemValue(fieldname,temp)
        Call doc.Save(True,False)       
        Set doc=dc.GetNextDocument(doc)   
    Wend
   
   
    Exit Function
' prrompt the errors that may result because of abrupt termination   
errHandler:
    Msgbox Error+" on line "+Cstr(Erl)+" in scriptLibrary Function-enableOrDisable"
    Exit Function
   
End Function

No comments:

Post a Comment