Pages

Thursday, January 28, 2010

Open database Dialog - Lotusscript - In Action

The following is a reusable fragment of work which can be used in various applications to help user choose databases and get their details of their file path and server name, instead of typing them explicitly in fields.

Following is a procedure that will illustrate the usage of open database dialog triggered using lotus script.

1. Create a lotus notes form, add a check box and a couple of fields as found in the following image



In the on exiting event of the check box put the following code(change the parameters values to suit your field names)

Call getDBFile("checkboxName","serverFieldName","dBPathFieldName")

 2. Now check the "Run Exiting/OnChange events after value change" checkbox in the advanced tab of the check box properties as mentioned below

3.  Copy the following function and add it to your form global or where ever you can call it from

Function getDBFile(chkField As String,dbServerField As String,dbPathfield As String) As Boolean
   
    'mark the flow of control moving inside the current function
    getDBFile=False
   
    'declare all variables and objects necessary for further manipulation
    Dim workspace As New NotesUIWorkspace
    Dim session As New NotesSession
    Dim uidoc As NotesUIDocument
    Dim currDoc As NotesDocument
    Dim currDB As NotesDatabase
    Dim dbServer As NotesName
   
    Dim selectedValue As String
    Dim empDBObj As Variant
   
    'handle errors in case of abrupt termination
    On Error Goto errHandler
   
   
    'set the handle of the current document
    Set uidoc = workspace.CurrentDocument
   
    'set the back end handle of the current document
    Set currDoc=uidoc.Document
   
   
    'if the selected value is of type 1 then ask the user to chose a database and populate the choosen db's
    'server and file path into the server and database path field
    selectedValue=currDoc.getitemvalue(chkField)(0)
    If selectedValue<>"1" Then Exit Function
   
    empDBObj= workspace.Prompt(13,"Database List","Choose Employee Database")
    If Not Isempty(empDBObj) Then
        Set dbServer=session.CreateName(empDBObj(0))
        Call currDoc.ReplaceItemValue(dbServerField,dbServer.Abbreviated)
        Call currDoc.ReplaceItemValue(dbPathfield,empDBObj(1))       
    End If
   
    Call currDoc.replaceitemvalue(chkField,"")
   
    getDBFile=True
    Exit Function
    'log the error that resulted in abrupt termination of the process
errHandler:
    Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***"   _
    & Cstr(Err) & "*** in ""Globals"" in form ""Database Configuration"""
    Exit Function
End Function


4. Now save and preview the form in Notes Client. Once the form is open in the notes client click the check box.
This will bring up the open database dialog as indicated below,

5. Choose your database and click open on the dialog box. This will automatically populate the databases in the empty fields as follows,


2 comments:

  1. We have @Prompt([ChoseDatabase]) in formula luanguage.

    If u find the way to do in xpage, please post it.

    ReplyDelete
  2. My guess is its quite similar to how the various names lookup popup codes available for the web apps. Its just that you can obtain them and modify them to lookup catalog.nsf instead of names.nsf.

    With some tinkering you can find the pros and cons of the same and use it to your advantage

    ReplyDelete