Running agent from xpages view

I am trying to run an agent in the OnClick of a button in my xpages view. I am using server-side Javascript. Every time I run the code below I get no errors as if its running correctly, it even executes a second action that follows the first. However when I check the logs my agent is never executed. When I change the code to anything else I get error 500 as if the code is wrong but was correct in the first place. I would appreciate any advice on the matter.

var database = session.getDatabase(session.getServerName(), “v_dir\voltest.nsf”);

var ag:NotesAgent = database.getAgent(“(RemoveCalc)”);

ag.runOnServer;

Subject: RunOnServer

So you proved that the problem is with your RunOnServer method.

RunOnSever method is designed to run from Notes client on the server.

It is not appropriate to execute from the web, and behind the schenes it is mapped to run.

To remove that mapping step, try replacing your RunOnServer statement with the example below, using

run method and parenthesis for complete syntax specification.

agent.run();

Subject: Re: Running agent from xpages view

Should it be ag.runOnServer() ? Your code may be thinking runOnServer is a property, not a method.

Subject: Is database on the same server as the agent (Local server) or remote server?

If you are trying to open local database use empty string for the server name. Your agent is already on the server.

When you specify a server name, it means a different server from the one where the agent

is running and then there is an extra security setting is necessary. The server whose data you are harvesting need to give permission to your server to do it. It is called “trusted server” field in the Security Tab of Domino Directly.

It is best not to set it if you don’t need it, as it is always better to run with the minimum you need.

Subject: Still not working

Thank you for the suggestions, I have given them both a try separately as well as together. Yes the removal of the server name does work but according to my print log the code is still failing on the runonserver line of code. Both entries below give me HTTP:500 error, I also made sure the correct signer was listed in the security settings of the server document.

Error given on server

08/12/2009 10:12:11 AM HTTP JVM: SEVERE: CLFAD####E: Exception thrown

08/12/2009 10:12:11 AM HTTP JVM: SEVERE: CLFAD####E: Exception occurred servicing request for: /v_dir/volsvl.nsf/test3.xsp - HTTP Code: 500

1st attempt

var database = session.getDatabase(“”,“v_dir\voltest.nsf”);

var ag:NotesAgent = database.getAgent(“(RemoveCalc)”);

ag.runOnServer();

2nd attempt

var database = session.getDatabase(“”,“v_dir\voltest.nsf”);

var ag:NotesAgent = database.getAgent(“(RemoveCalc)”);

ag.runOnServer;

Subject: Hidden agent

I would try not using a hidden agent (name in parenthesis). Make a copy called “test” (no parenthesis) and try loading that agent.

If this was a security problem you would see an error on the server console with the error.

Subject: Didn’t work either

I made the change of the agent and this time the code failed on the agent line of code. But when I changed it back the code did not fail however the agent didn’t run either.

Subject: Simplify…

So see if you can get that agent to run from just a url page, without having it run from xpages.This will help you narrow down the problem and convince yourself that the agent in fact is found and

can be executed (security is set up correctly, etc)

To run an agent directly from you url all you need to is specify agent name after the database name

http://yourserver/youdb.nsf/youragentname

Subject: Narrowing Down

I tried your idea and I did put the path of the agent into a url and yes it was found, it ran and did work.

Any ideas on what the problem might be then?

Subject: response goes here

I must have been pointing to the wrong post

Subject: Solved

Thank you so much, it works now. I posted the working code below.

var db:NotesDatabase = session.getDatabase(session.getServerName(), “v_dir\voltest.nsf”);

 var ag = database.getAgent("(RemoveCalc)");

 ag.run();

Subject: For diagnostic purposes

can you try dropping the parenthesis and see if it works?I want to know if there is a problem in RunOnServer to Run mapping, or whether the problem was caused by not having parethensis.

Thank you very much!