Tuesday, November 07, 2006

SNTT - Updating a UI document from an agent called with RunOnServer

Here's a technique to run an agent on the server, close the UI document, and have it reopen showing the updates done in the agent. In this case my agent is issuing LC LSX calls to update data from DB2. The following code is in a Hotspot button on the document. The tricky part here is knowing to use Delete on the NotesDocument. You have to delete the document from the object cache after the agent runs to force it refresh when you reopen it.
Sub Click(Source As Button)
Dim uiws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim db As NotesDatabase
Dim agent As NotesAgent
Dim doc As NotesDocument
Dim noteid As String

Set uidoc = uiws.CurrentDocument
Call uidoc.Save

Set db = uiws.CurrentDatabase.Database
Set agent = db.GetAgent("Get Account Info")
Set doc = uidoc.Document
noteid = doc.NoteID

If agent.RunOnServer(doc.NoteID) <> 0 Then
Msgbox "There was an error looking up the account information.", 48 _
, "New Account Setup"
End If

Call uidoc.Close(True)
Delete doc
Set doc = db.GetDocumentByID(noteid)
Set uidoc = uiws.EditDocument(True, doc)
End Sub

This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.



  1. Good tip. Here's a way to extend it..

    I do a lot of interaction with an AS400 from Domino on the AS400 and Domino on a Win Server 2003. I get data using : JDBC, LCLSX, ODBC and can retrieve data to the back end, front end, web, whatever. To prevent you from having to close your Ui document, write the data to a user document in the backend.

    So instead, do something like

    set doc_user = getMyUserDoc()
    noteid = doc_user.NoteID
    if agent.RunOnServer(noteid)...

    set doc_user = db.GetDocumentById(noteid)
    then write to your uidoc

    Neil and Andre put me onto this method, it works great, for more details goto:

  2. Nick, for some reason the URL you pasted isn't being shown completely. I guess there's some problem with the Blogger comment system. You can put it in a link tag and it'll get converted.

    I saw some similar techniques to what you're describing on Notes.net, but I didn't really understand why it's a bad thing to close the UI document. It's a lot less work than updating the NotesDocument AND updating the NotesUIDocument. I suppose for web apps it might be a bigger deal, but I don't do web apps.

  3. That's what I used as a basis for what I'm doing. :) The big difference is instead of using a profile as an intermediary I'm using the already loaded NotesDocument. The only downside is I have to close the UI document to show the changes. For me the big benefit is I don't have to save data temporarily, merge it with the UI document, then have all the deletion stubs from the profile documents floating around

    There are times when the profile-oriented approach would be the best one, but for me in this situation I saw it as a lot of work without any gain. I wanted to show another solution.