Question

How to pass the Document context in Xpages while calling an Agent? In Xpage, I am in need of calling a java agent with documentcontext from my Xpage, And also I am in need of passing my current document as a parameter...

In Lotuscript we can do it as easily without saving the current document, but in Xpage I am using the following code., document1 is a current document.

var agent=database.getAgent("AgentName");
agent.runWithDocumentContext(currentDocument.getDocument());

This code I am not able to get the values of my current document's items, but if I will use the following code,

var agent=database.getAgent("AgentName");
document1.save();
agent.runWithDocumentContext(currentDocument.getDocument());

I can get the item value of the current document... But I do not want to save the document, without saving the document I need to get the item value of item.

Please give any nice solution for that...

Was it helpful?

Solution

agent.runWithDocumentContext(currentDocument.getDocument(true)). This will put all the new values inside the backend doc, so it works the same way as lotusscript does. Also, if you need to have the currentdocument computed with the notes form, set the 'computewithnotesform' property of the datasource to 'onload' or 'both'.

OTHER TIPS

Since when there can be more then one document source on the xPage, I use ParameterDocID...

var id = document1.getDocument().getNoteID();
var agent = database.getAgent("MyAgent");
agent.run(id)

and in the agent...

Call GetDocument(agent.ParameterDocID)

...

Public Sub GetDocument(DocID As String)
On Error GoTo eh

Set Doc = Db.GetDocumentByID(DocID)

es:
Exit Sub
eh:
Resume es
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top