Manage Learn to apply best practices and optimize your operations.

Moving To A Particular Document In A View Using Script (In Notes 4.6)

The only way (I know of) to accomplish this is via the SelectDocument Method in
the NotesUIView Class. The problem is that the NotesUIView Class is only
available through the QueryRecalc event in the view.

The Solution involves the following:

1. The view you want to open to a particular position.
2. A hidden view with all documents sorted by a key value (in my case I used a
section number).
3. Script code in the QueryRecalc event in 1. that uses 2. to find the right
document and the SelectDocument method to select it in 1.
4. Some @Function code that triggers the QueryRecalc Event in 1.
Here is some LotusScript code to paste into the QueryRecalc event. I use
Environment variables to pass parameters to control the execution of the code:

Sub Queryrecalc(Source As Notesuiview, Continue As Variant)
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim view As NotesView
Dim db As NotesDatabase
Dim doc As NotesDocument

Set db = session.CurrentDatabase

searchDocument = session.GetEnvironmentString("EnvSearchDocument")
key = session.GetEnvironmentString("EnvKey")

If searchDocument = "Yes" Then
'Now reset to prevent the code from being activated by the next view
searchDocument = "No"
Call session.SetEnvironmentVar("EnvSearchDocument", searchDocument)
Set view = db.GetView("vKEYLOOKUP") 'Hidden lookup view with key
values sorted
Set doc = view.GetDocumentByKey(key)
If Not doc Is Nothing Then
Call Source.SelectDocument(doc) 'This will do the job
Messagebox "The document with the key value " + key + " was not
found", 64, "*Find Document"
End If
End If
End Sub

The following @Function code will execute the Script code when the view is
refreshed with @Command([ViewRefreshFields]). It lets the user input a a key
value and moves to the corresponding document in the view. In my case i used it
to let the user enter a section number and move the view marker to the right
If the Preview Pane is turned on the document will be displayed instantly.

_section := @Prompt([OKCANCELEDIT]; "Find Document"; "Enter a key"; ""; "");
@Environment("EnvKey"; _key);
@Environment("EnvSearchDocument"; "Yes");
@Command([OpenView]; "vVIEWTOOPEN");

Dig Deeper on Domino Resources - Part 4

  • Favorite iSeries cheat sheets

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