1

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...

Ben Dubuc
  • 523
  • 3
  • 14
  • I would like to be able to redirect to a generic error xpage, passing some error code in the URL, but how do redirect to the error.xsp page from the Lotus Script agent??? That would be a good enough solution! – Ben Dubuc Apr 01 '15 at 17:50

2 Answers2

3

I recommend to use the method:

agent.runWithDocumentContext(doc); // << ssjs

then in the agent you get the document updated with the last changes:

set doc = ses.documentContext ' << ls

Other option would be to use the property webQuerySaveAgent of the DocumentDataSource

Txemanu
  • 449
  • 2
  • 7
  • That is what I'm already doing, but I am trying to catch the errors that might occur in the agent. Errors might cause the document not to be saved, so I can't really count on a value in a field to let me know if all went well. I'd also like to pinpoint the code that caused the error as precise as possible. – Ben Dubuc Apr 01 '15 at 17:53
  • 1
    maybe you can call the agent in the querysave event (or webQuerySaveAgent) and if in the agent something goes wrong, fill a field of the document (doc.error = "1") and check this field after executing the agent in ssjs. If the field error has the value "1" returning false in the event you cancel the save action (not sure 100% now) For this technique the runWithDocumentContext is great. – Txemanu Apr 01 '15 at 17:58
2

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

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • 1
    Thanks Stephan. I used the agent as it was already built in the IBM wiki, but I was already reconsidering rebuilding the functionality in SSJS or JAva, as we do not create content through the Notes client. The IBM code was done that way because of the dual clients, but it causes some issues that we won't have if the code is rewritten. The IBM code was good to demonstrate the versionning concept to the users, but for maintenance and performance issues, it will be Worth rewritting ithat part for sure. – Ben Dubuc Apr 02 '15 at 14:40