Tuesday, August 16, 2011

Working with In Memory Documents in XPages

Following is a simple demonstration of how documents in memory can be used to communicate between XPages and Agents.The beauty in the following description is that the document in memory is never being saved. That is an awesome stuff that I feel is really helpful for developers in many occations

Create an XPage with a couple of input fields named "boxA" and "boxB" as shown in the following image
Now add a button and label it as you desire and add the following code to it

The code displayed in the above mentioned image does the following,
  1. it simply creates a document on the fly named "inMemoryDoc"
  2. Handle to an agent present in the backend is obtained
  3. The agent is asked to be executed with the inMemoryDoc created in the first step as documentcontext
  4. The inMemory document gets updated (not saved) in the backend and the updated values are asked to be displayed on the UI using the getComponent("").setValue() methods.

The code fragment in the agent that resides on the backend is as follows

So as a result when you preview the XPage on the browser and hit the button the out put will be as follows

If you get any errors ensure that the credentials mentioned in the following post are met,

Hope this helps :)


  1. Karthik, is there a way I can trigger an agent using SSJS but not wait untill the agent has run?

  2. Yes. I know of a particular way. But thats a bit complicated. You may have to split your code and redistribute them across multiple buttons.

    The idea is you have a way to trigger client side script after server side script completes execution. You can search for onComplete event in this blog to get idea about it.

    Tell me about what you are trying to accomplish and may be I can tell you about what can be done

  3. We can also pass the values from xpages to Lotus Script too...

  4. Is there a way to show an in memory document to the user? I'm thinking of creating a draft from a "main" document but the draft would be an in memory document displayed to the user using a page.

    thanks ;)