Generate a Document in Another Database

This routine illustrates how to create a button that, when clicked, composes a document in another database. This approach can be used to

The button can then be incorporated in an existing Notes database application or inserted into an email and distributed to users. This solution creates the new document through the user interface (or via front-end objects).

How It Works

To create a document in another database, you will need to gather information pertaining to the database, form, and fields. After this information has been determined, you can instantiate a NotesDatabase object that references the secondary database. Then, using the NotesDocument class, you can generate the document, preset field values, and display the form via the ComposeDocument method.

Implementation

The following outlines the process to create an action button that creates a form in another database.

Step 1.

Verify that users have appropriate access to the target database. Users must have authority to access the target database. If the user that clicks the button does not have at a minimum "Depositor" access, then he or she will not be able to create a document.

 

   

Step 2.

Gather design properties for the target database. Determine the Domino server name, directory path, and database name for the target application. This can be achieved by manually opening the database using the Lotus Notes client and selecting the File > Database > Properties menu options. This will display a dialog box similar to Figure 13.24. Make note of the server name (e.g., IBMTOOLS) and filename information (e.g., AppsRFS.nsf, where Apps is the directory path and RFS.NSF is the database name).

 

Figure 13.24. Database properties dialog

 
   

Step 3.

Determine the default form name. Open the target database and open an existing document. Select the File > Document Properties menu option. Switch to tab 2. Make note of the value assigned to the Form field (see Figure 13.25).

 

Figure 13.25. Field names and values for a document in a database

 
   

Step 4.

Create an action button in the current database and insert the following LotusScript code in the Programmer's pane. Then set the database connection field values (located at the top of the code). Replace SERVER, PATH, DATABASE, and FORM with values that reference the target database.

 

Note

A double back-slash must be used to separate the directory path and the database file name. If the Notes application is stored in the server root directory, then simply omit the directory and back-slash values.

Sub Click(Source As Button) Dim mydb As NotesDatabase Dim w As NotesUIWorkspace Dim uidoc As NotesUIDocument Dim server As String Dim DBPath As String Dim DBForm As String '----------------------------------------------------------------- ' Set target database information '----------------------------------------------------------------- Server = "SERVER" DBPath = "PATH\DATABASE.NSF" DBForm = "FORM" '----------------------------------------------------------------- ' Attempt connection to target server '----------------------------------------------------------------- Print "Connection established to target database" Set mydb = New NotesDatabase("", "") Call mydb.Open(Server, DBPath) If (mydb Is Nothing) Then Msgbox "Warning: unable to open target database." Else '----------------------------------------------------------------- ' Create new document '----------------------------------------------------------------- Print "Connection established to: " + mydb.FileName Set w = New NotesUIWorkspace Print "Composing change management record" Set uidoc = w.ComposeDocument (Server, DBPath, DBForm) '----------------------------------------------------------------- ' Set default values on target form (optional) '----------------------------------------------------------------- Print "Setting default values" Call uidoc.FieldSetText ("FIELD1", "VALUE1") Call uidoc.FieldSetText ("FIELD2", "VALUE2") End If Print "Generate document complete." End Sub  

Step 5.

Next, return to the target database and either open or select a form in the database. Select the File > Document Properties menu options. Switch to tab 2 and locate the field called FORM. Assign this value to the DBForm variable in the LotusScript routine. (Alternatively, if you have Designer- and Manager-level access to the database, you can look up the form name in the Designer client.)

 

Step 6.

With the document properties dialog still open, identify the target fields to populate with values and update the LotusScript.

 

Tip

If you are unable to determine the target fields from the document properties dialog, try creating a new "local copy" of the target database (using the "design only" option) and open the form in Designer to determine the target fields to populate. If you are unable to make a new copy, then the database design may be restricted.

Категории