I have written lotusscript code in Agent, i need to run the agent by on clicking the button in Xpage.
How could i achieve?
Thanks in advance
A problem with this solution could be that when you want to use data which is manipulated in the agent you have to reload the notes document in your xpage. This can be done with the following lines of code:
var ag = database.getAgent("agentname");
if(ag != null){
var id = doc.noteid;
ag.runonserver(id);
doc.recycle();
doc = database.getdocumentbyid(id);
// check if the agent did its job.
// if so do stuff otherwhise report this to the user?
}
Since version 8.5.2 there is a new method added to the agent class
agent.runWithDocumentContext(NotesDocument doc);
This method uses the in memory document of the xPage. Therefore you don't need to save your document in the agent itself but you can make your changes and exit the agent code. The xpage can directly make use of the changes made. This saves you a lot of hassle with checking if the agent did his job, reloading the document etc etc.
For this to work you have to set the options of your agent to