Domino Code Fragment

Code Name*
Auto Refreshing a UI document from a back end document.
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.146.152.99
Description*
The original goal was to open a UI doc, and keep it open while periodically refreshing the fields from the back end doc.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

I got around to this again, and made it work.

The story so far...
The original goal was to open a UI doc, and keep it open while periodically refreshing the fields from the back end doc.

The back end doc would be updated independantly by another agent.
The UI doc was to be read-only, so that there was no possibility of the user entering bogus data into the backed doc via the UI doc.
There are some problems with this approach... It is not possible to refresh the UI doc using ComputeWithForm in this case because the BE doc is updated by another source, so this method won't work (its written in the help docs if you read carefully). The various work-arounds I tried still did not help. The next approach I tried was to have an agent get the BE data and open//close/update/open a UI doc. This proved to be messy - you have to write your own timer (Notestimer object doesn't work in agents), the UI doc never displayed fully (at least on my meager machine), and it still didn't work. Jan's suggestion got me thinking (and searching around in this forum) and rethinking my approach
.

Here's what I did in the end (and achieved the design goal):

The agent updating the BE doc (let's call it BEDoc) is unchanged. I created a new form, copying the field names of the BEDoc (copy paste actually).
The new form is now the one that will be opened by the user as UIDoc. Make all the fields on UIDoc Computed, and add a computed text field called 'SaveOptions' with a value of "0". This prevents any fields being saved even if ctrl-S is pressed and you don't get the Yes/No/Cancel dialog; effectively, this makes the form read only.

In the declarations section:

Dim elapsedTimer As NotesTimer
Dim session As NotesSession
Dim db As NotesDatabase
Dim ws As NotesUIWorkspace
Dim UIDoc As NotesUIDocument
Dim BEDoc As NotesDocument
Dim BEDocUNID As String


In the PostOpen sub:
Set session = New NotesSession
Set ws = New NotesUIWorkspace
Set db = session.CurrentDatabase
Set BEDoc = (you can work out your own way to get this -
I open a specific BE view and get the first doc)
BEDocUNID = BEDoc.UniversalID
Set UIDoc = ws.CurrentDocument
'Call the timer every ten seconds
Set elapsedTimer = New NotesTimer(10, "Update Timer")
'You might want to update the fields here as well, since the timer
' has not yet kicked in.
On Event Alarm From elapsedTimer Call TimerHandler


In the TimerHandler sub:
Set BEDoc = Nothing
Set BEDoc = db.GetDocumentByUNID(BEDocUNID)
Call UIDoc.FieldSetText("YourField",_
Cstr(BEDoc.YourField(0)))


Later I added an editable field and some code to UIDoc to enable me to dynamically update the timer interval.

As Nathan T Freeman mentions, document preview won't work here as the UI doc is never saved (at least not in my design!). I'd be interested to hear if anyone sees any other limitations to this approach.

Thanks for everyone's attention and efforts - great team work and SUCCESS!!!

-Rob.


Extra FT Keywords: Reload Timer BackEnd Updating