Triggering agents from server side javascript in XPages is easy. How ever obtaining the response from the agents once the lotus script agent completes execution and displaying the same on the xpage was always a challenge to me. The following is a way helped me achieve it,
/***************************************************/
importPackage(java.net);
importPackage(java.io);
//create a url object by passing the lotusscript agent's url and ensure that you have some print statements in your agent
var agent:URL = new URL("Agent URL");
//create a connection with the agent's url provided
var agentConnection:URLConnection = agent.openConnection();
//open a buffered reader that gets the stream of response from the agent connection
var inputReader:BufferedReader = new BufferedReader(new InputStreamReader(agentConnection.getInputStream()));
//read the output line by line and store them in a string
var res:String="";
while ((inputLine = inputReader.readLine()) != null) {
res+=inputLine;
}
//update the result to a output field on the XPage to view the same visually
getComponent("output").setValue(res);
/***************************************************/
This attempt was successful and I was able to recieve responses on the XPage but is a Synchronous way. Hence you may have to wait until the agent gets executed and the response is obtained.
Am yet to find the same to do in a Asynchronous way.
Hope this helps :)
I guess your agent is printing out the content using "print"
ReplyDeleteYep thats right... is there an other way to do it!!!!!
ReplyDeletejust curious!!!
why do you need to get data from and agent?
ReplyDeleteWhen XPage enabling existing applications, it is faster to reuse the existing lotusscript functions right...!!! So I call them into XPages by converting them into agents and obtain the specific funtion's return value as response.
ReplyDeleteThe end user's use both 7 and 8.5.2... so i am supposed to minimize duplications to reduce complications in maintainence..
Hope I make sense :)
what if I want to write multiple values back to the xpage?
ReplyDeleteeg
doc.FirstName = apCardScanData(4)
doc.LastName = apCardScanData(4)
doc is in memory document on XPage
I had this question 6 months back. The following stuff helped me resolve it.
ReplyDeletehttp://www-10.lotus.com/ldd/ddwiki.nsf/dx/XPages_and_Calling_Agents_Using_an_In-Memory_Document
Try it out and let me know if you dont get it.... Possibly I will do a simple post on this soon
Hope that helps :)
@quintessens : Please check the following post that I have added to answer your query
ReplyDeleteWorking with in memory documents