dominoGuru.com
Your Development & Design Resource
Quick Hack: Controlling the Render Form of a NotesDocument in the Lotus Notes Client
07/29/2009 12:03 PM by Chris Toohey
As I am ever discussing the need to separate the NotesDocument from Form Design Element binding - in other words, separating UI from the DataStore - I thought that I'd pass you a quick tip.
First, the scenario:
I have a Lotus Notes Client-based application that contains a simple document approval engine. Each approval document is a response NotesDocument to the parent NotesDocument which contains the overall status and miscellaneous document data. There is a business logic to which NotesDocument and Form Design Element is displayed based on who you are in the system or the current state of the NotesDocument.
For example, while the NotesView shows me the given document, I might be launching my individual review response NotesDocument, or a reader response NotesDocument, or the actual document.
Use Form Formula? Well, I do... but not how you might suspect. See, remember that I might need to launch the document or one of it's specific responses (my review NotesDocument).
Simply put, I need to be able to control what's opened regardless of how it's opened.
The tip:
document is not a UI component per se, but rather a "stub" Design Element that relies on the application logic to render a given NotesDocument via it's PostOpen event.
Example A
Sub Postopen(Source As Notesuidocument)
Dim s As New NotesSession
Dim w As New NotesUIWorkspace
Dim rcol As NotesDocumentCollection
Dim rdoc As NotesDocument
Set db = s.CurrentDatabase
Set rdoc = Nothing
Set rcol = source.Document.Responses
If (rcol.Count > 0) Then
Call rcol.FTSearch(|[reviewer] = "| & s.CommonUserName & |"|,
0)
Set rdoc = rcol.GetFirstDocument
Call w.EditDocument(True, rdoc)
End If
Call source.Close(True)
End Sub
Pretty basic right? Well, here's the trick that will allow you to open that - in the above case - review NotesDocument with any Form you wish.
Example:
Sub Postopen(Source As Notesuidocument)
Dim s As New NotesSession
Dim w As New NotesUIWorkspace
Dim rcol As NotesDocumentCollection
Dim rdoc As NotesDocument
Set db = s.CurrentDatabase
Set rdoc = Nothing
Set rcol = source.Document.Responses
If (rcol.Count > 0) Then
Call rcol.FTSearch(|[reviewer] = "| & s.CommonUserName & |"|,
0)
Set rdoc = rcol.GetFirstDocument
Call rdoc.replaceItemValue("form",
"reader")
Call w.EditDocument(True, rdoc)
End If
Call source.Close(True)
End Sub
Pretty simple right?
This allows me to open rdoc with the reader Form Design Element.
The only caveat to this approach would be if I needed to actually save content back to rdoc but wanted to ensure that the form NotesItem wasn't overwritten with my reader value.
... which is something I'll save for tomorrow's post.