I am calling a lotusscript agent from the PostSave event of an xpage (taken from the IBM Wiki Template). I would like to add some error trapping so if something happens (I had cases of "attachments missing... run compact to fix this" error), the application would at least warn the user that something went wrong.
Do I need to put the error trapping code in the agent? Does it belong in the PostSave event of the xpages?
The agent is called that way:
<xp:this.data>
<xp:dominoDocument var="pageDocument" formName="fPage"
action="openDocument" ignoreRequestParams="false"
computeWithForm="onsave">
<xp:this.postSaveDocument><![CDATA[#{javascript:var agent = database.getAgent("XPSavePage");
agent.runOnServer(pageDocument.getDocument().getNoteID());}]]>
</xp:this.postSaveDocument>
</xp:dominoDocument>
<xp:this.data>
The agent is working great, but on some documents, we do have a missing attachments error, due to some conversion errors and other cases (persitence related, most probably). But I have no clue on how to trap if an error occured in the Lotus Script agent...
The agent has ZERO visibility to the calling environment, short of the DocumentContext. So you need to write any status back into the document and check that value in your XPage. If you want to be very cautious, you set the status to 'AgentFailed' and let the agent update it with either 'success' or a more specific error. This way you trap errors where the agent couldn't write back into the document.
While you are on it: improve your application's response time by taking out the start of the agent runtime - write your code in a bean. SessionAsSigner gives you elevated rights you might need