Domino Code Fragment

Code Name*
How to Display a Document, that Isn't the Current Document, w/ LotusScript
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.221.13.173
Description*
Illustrates one way to get a handle to a particular document (via a backend method) and then make the document the new UI document that displays on the screen. Specifically, the application performs the following actions:
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Problem:
Using LotusScript, you would like to display a particular document on the screen. The

document is not the current document (which you could then display on the screen using
the NotesUIDocument method). Instead, the document is one that is identified through a
LotusScript backend method (the document meets, for example, a certain criteria). How,
using LotusScript, can this particular document be displayed on the screen?

Solution:
Below is a sample application that
illustrates one way to get a handle to a particular
document (via a backend method) and then make the document the new UI document that
displays on the screen. Specifically, the application performs the following actions:

- Reads the UN-ID out of the instance of NotesDocument.
- Opens a temporary view selecting the document having the UN-ID.
- Opens the currently selected document.
- Switches to the temporary view.
- Closes the temporary view.


The exact steps to create this application are listed below.

1. Create a view with following attributes:

View Name: (DocUniqueID)
No Response Hierarchy: Enabled
Refresh Frequency: Automatic
View May Be Used By: All Users
Selection Formula: SELECT @All
Column Number: 1
Column Formula: @Text(@DocumentUniqueID);
Sorting: Ascending


2. Create a hidden script agent called (DisplayDoc).

'The subprogram Initialize is a sample script to get an instance of NotesDocument.
'In this script, it looks for the first document in the view "test1."


Sub Initialize
Dim ws As New NotesUiWorkspace
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument


Set db = sess.CurrentDatabase
Set view = db.GetView("test1")
Set doc = view.GetNthDocument(1)
DisplayDocument doc
End Sub


Function DisplayDocument(doc As NotesDocument) As Integer
Dim ws As New NotesUiWorkspace
Dim db As NotesDatabase
Dim view As NotesView
Dim viewDoc As NotesDocument


Set db = doc.ParentDatabase
Set view = db.GetView("(DocUniqueID)")
Set viewDoc = db.GetDocumentByUnID(view.UniversalID)
ws.OpenDatabase db.Server, db.FilePath, "(DocUniqueID)", doc.UniversalID, True
ws.EditDocument False
ws.OpenDatabase db.Server, db.FilePath, "(DocUniqueID)", ,False
'this line brings the temporary view to the top
End Function


3. Create a button with the following formula. (Note that @functions must be used to close
  the temporary view.)

@Command([ToolsRunMacro]; "(DisplayDoc)");
@Command([FileCloseWindow])