This, that and the other (may contain nuts)

XPages - webQuerySave equivalent or using Lotusscript to process data

Steve Castledine  7 November 2008 09:28:52
Image:XPages - webQuerySave equivalent or using Lotusscript to process data

I'm planning some "how to" XPages posts for "Domino Developers", in the meantime here's something for this week's "tip" theme.

You may currently have a lot of logic sitting in Lotusscript agents or libraries, and you want to use these when trying out XPages, as its probably a big job to rewrite all of them from scratch in server side JavaScript etc (especially just for the purpose of testing or proof of concept).

Whilst in the long term, using the XPages way of doing things is probably better, and I'm told there will also be improvements in this area, there is a way of leveraging say LotusScript based webQuerySave agents or script libraries etc.

You can do this by using the agent.RunOnServer(docid) command (as when the agent executes we do not have the usual documentcontext handle) to run your agent after an xPage document save. The difference to note, is when you perform any actions on the document (via your code) it has already been saved so you are not able to do anything before save (these are the actions you will need to write in XPages javascript).

To do this you would create an agent as normal, and instead of collecting the document reference via session.documentContext, instead use agent.ParameterDocID via Set doc = db.GetDocumentByID(agent.ParameterDocID):

Image:XPages - webQuerySave equivalent or using Lotusscript to process data
Then in your XPage, navigate to "Events > Data > Your Document as specified already as a data source > postSaveDocument" add an action "Basic > Execute Script".

You can then use the code var agent=database.getAgent("youragent"); to get a handle to the agent and then agent.runOnServer(document1.getNoteID()); to pass the document reference to your agent (which we collected using agent.ParameterDocID).

Image:XPages - webQuerySave equivalent or using Lotusscript to process data

Image:XPages - webQuerySave equivalent or using Lotusscript to process data