Manage Learn to apply best practices and optimize your operations.

Switching Forms Over One Notes Document

This simple script allows you to use multiple forms to view one Notes document.
I developed this code after trying to use the @Command ViewSwitchForm. I could
not get the command to work in a view that uses a Form Formula, so I came up
with this simple method instead.

For coding ease, I placed the two subroutines in a script library, but that is
up to you. Please try it out and let me know if you have problems.
First of all I created a script Library called "UTILS". In this library I
created two subroutines "SwitchTrigger" and "SwitchForm".

For this example, lets assume we have three forms,AppForm,FormA and FormB, that
we want to use to view a document with.

In the forms you will need to place USE "UTILS" in the Options section of FORM
events. Do not place it in the GLOBAL Form events because the event may lose
the handle to those option in the TERMINATE event.
Next create the action buttons, or hotspots that the user will click to switch
forms. Add the following code to the buttons:
Call SwitchTrigger(FormX)'Whichever form you want to switch to, eg. "FormA"

In the code below you will notice I set two environment vars PFormSwitch (the
form Name to Switch to) and FormSwitch (A flag that is set to true when
switching forms).

Here is the code for SwitchTrigger:
'This Sub is placed in the buttons or action that triggers the "SwitchForm" Sub
' to execute in the Terminate event of the form.

Sub SwitchTrigger (FormName As String)
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument

Set uidoc = ws.CurrentDocument
'Set the environment vars that will give "SwitchForm" the information it needs
'to switch the forms -- PFormSwitch = the form to switch to
' FormSwitch = the flag that lets you switch forms
Call session.SetenvironmentVar("PFormSwitch",FormName)
Call session.SetenvironmentVar("FormSwitch","1")
'If you want to save the doc automatically place Call uidoc.Save here.
Call uidoc.Close
End Sub

The uidoc.Close method will trigger the Terminate Event which should contain
the following code.

Call SwitchForm

Here is the code for SwitchForm:
Sub SwitchForm
Dim session As New notessession
Dim db As NotesDatabase
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument

'Grabs the value of an Environment Var that tells us if we can switch forms
Switch$ = session.Getenvironmentstring("FormSwitch")

If Switch$ = "1" Then
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
doc.Form = session.Getenvironmentstring("PFormSwitch")
Set uidoc = ws.EditDocument(True,doc)
'reset the environment var to turn the switch off
Call session.Setenvironmentvar("FormSwitch","0")
End If

End Sub

So here is the scenario... Users create a document using the form 'AppForm'.
Then another group of users want to process the applicant using FormA, so they
click the button "Switch to FormA" and the information from AppForm is
displayed in FormA. After the changes in FormA are made, the user switches to
FormB to enter more information about the applicant. So now you have ONE
document, viewed and edited by 3 different forms. Also if you want the
document saved with ONE Form name instead of the last one it was saved with,
just add a field called Form to each form that is computed to the value you
want the Form Name to be. eg. "AppForm"

This code is really easy to maintain if you use a subform to put all of the
code and buttons in and then place the subform in the appropriate forms.

Dig Deeper on Domino Resources - Part 6



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury