RunOnServer agents not returning an error but should

I am having trouble with a runonserver agent not failing when it should, so I created a simple test db with an agent and a form with an action to run the test agent. I tested it and can see the error on the server console but am unable to get anything other than success from runonserver.

Below is the test setup. Any idea why result is 0?

The called agent did not run to completion due to the error so I would expect to see something other than 0 for a result. Using “run” instead of “runonserver” has the same effect (result=0, no error returned)

Agent:

Sub Initialize

Dim x As Integer

Dim y As Integer

x=1/y 'divide by zero error

End Sub

'*********************************

Action in form:

Sub Click(Source As Button)

Dim session As New NotesSession

Dim theagent As NotesAgent

Dim db As notesdatabase

Dim result As Integer

Set db=session.CurrentDatabase

Set theagent=db.GetAgent("Cause Error")

result=theagent.RunOnServer

'result is 0, even with error

End Sub

Subject: RunOnServer agents not returning an error but should

The help is misleading. ROS returns success if the agent could be run. It does NOT indicate that the agent ran successfully, just that the attempt to run it was successful. If you want the agent to return a status you have to communicate with it via a temp doc and the agent must trap errors and return a status in the temp doc.

Subject: RunOnServer agents not returning an error but should

An error is returned if the method fails to invoke the agent. It does not return an error if the agent itself has a run time error. Agent FAQ has an example of how to return an error from the agent itself using parameter passing. The article that has this information is called something like “RunOnServer and passing parameters”. You will see it listed in the index of all agent article in the very first FAQ.