NotesAgent.runWithDocumentContext(doc) behaviour

28 July, 2011 10:49:20 Miguel Calvo  XPages  English  |  Comentarios (0)

I hadn't had the need of using the new 8.5.2 method runWithDocumentContext yet. It's useful to make use of your Java or LotusScript libraries in XPages development. It allows to simulate the "classic" WebQuerySave and WebQueryOpen events from SSJS.

You can pass an in-memory document to a LotusScript or Java agent that can instantiate it by using the NotesSession.DocumentContext ( in LS) property from the NotesSession LS class.

It's absolutelly necessary that the agent has the option "Run as web user" checked

Image:NotesAgent.runWithDocumentContext(doc) behaviour

if you don't want to get this cryptical error:

Exception occurred calling method NotesAgent.runWithDocumentContext(lotus.domino.local.Document) null

Testing its behaviour


To test its behaviour I'm using a LotusScript agent that changes the contents of a field in the document passed to it.

doc.field = "newvalue"

  • If you want to simulate a WQO event automatically, you must invoke it in the datasource postOpenDocument event in your XPage or in the afterPageLoad event of the XPage. The new value will be reflected in "Edit Box" or "Computed Field" controls binded to this field.
  • If you want to simulate a WQS event automatically, you must invoke it in the datasource querySaveDocument event in your XPage.
  • You don't have to save the document in the agent code.
  • IMPORTANT: Trying to simulate a WQS event, if you have a "Edit Box" control binded to the field, the value from the user interface overwrites the value set by your agent. (This differs from the WQS classic behaviour )


[More info at XPages and Calling Agents Using an In-Memory Document ]

Sé el primero en comentar la noticia

Deja una respuesta


Nota:  (No HTML - Los enlaces serán convertidos si están precedidos por http://)

¿ Recuérdame?