I have a simple action that contains the following code in a xpage’s postSaveDocument event:
var db:NotesDatabase = session.getDatabase(session.getServerName(), “TimeOffxp.nsf”);
var agent:NotesAgent = db.getAgent(“(SaveProfile)”);
agent.runOnServer(document1.getNoteID());
Although I already delete all code in the agent (an empty empty agent), I still got the “The page cannot display - http 500” error when I save the document. I also try the same code in the “querySaveDocument” event and got the same error.
Please advice if anything I did wrong or I miss somthing. Thanks.
Subject: Re: Run Lotusscript agent from Xpage
A couple of thoughts:
-
is your agent set to run on selected documents? That may cause it to fail.
-
is your agent running? Check the agent log.
-
is anything being logged to the server log?
-
make sure you’re enabled the ‘Display default error page’ on the XPages tab of the Application Properties. This will tell you if you’ve got an error in your server-side javascript code.
-
is there a problem with code on the page you’re going to after save of the XPage? Try sending it to a basic pge with no coding.
This might help you identify the cause of the prolem.
Regards
Paul
Subject: Re problem run lotusscript agent from Xpage
Thank you for your response. Here are my answers to your questions:
- is your agent set to run on selected documents? That may cause it to fail.
No. this was an old “WebQuerySave” agent. It is set to run from “Agent List” and the target is set to “None”
- is your agent running? Check the agent log.
No agent log.
- is anything being logged to the server log?
The application is in a local pc and there is no entry in local log.nsf.
- make sure you’re enabled the ‘Display default error page’ on the XPages tab of the Application Properties. This will tell you if you’ve got an error in your server-side javascript code.
I cannot find the “Xpages tab” in the application (database) properties.
- is there a problem with code on the page you’re going to after save of the XPage? Try sending it to a basic pge with no coding.
If I remove the “agent.runOnServer(document1.getNoteID());” Everything is fine. Like I said, it is a empty agent (no line). So the problem is caused by “agent.runOnServer(document1.getNoteID());”
Subject: Re problem run lotusscript agent from Xpage
You need to open the Application Properties from Domino Designer, then you get the XPages tab. See Declan Lynch’s course on XPages, specifically this part:Learning XPages Part 41 : Debugging Your Code | Dec's Dom Blog
notesdocument.getNoteID() gets the correct value, so there’s something wrong with getting the agent.
I’ve tried putting a button in to call an agent in the same database and run on server, passing a noteID and msgboxing a value from the relevant document in the agent and it works fine. My code was:
var myAgent:NotesAgent = database.getAgent(“test”);
myAgent.runOnServer(profile.getNoteID())
“profile” is the DominoDocument data source on the XPage. My agent was also Agent List with target None. I notice your code has the agent in brackets, by accident I missed those out and it found the agent fine, so I’m not sure if tha’ the problem. Switching on the default error page will show you which line the code is faiing on though.
Regards
Paul
Subject: Re problem run lotusscript agent from xpage
Finally, it works now. After I enable the error tracking, it said “document1” is an invalid object. So I change it to “Domino.document1” and it works. I appreciate your help. One more question, can I run lotusscript agent in any place in a xpage ( just like you mention in a button) or have to follow the old rule, WebQueryOpen and WebQuerySave only?
Subject: Re problem run lotusscript agent from xpage
It sounds strange that you had to do Domino.document1. You should just need to use the name you gave the datasource when referencing it is server-side javascript - this should be visible in the list of Global Objects when you’re in the Script Editor.
You should be able to call a LotusScript agent from anywhere on the form. Just bear in mind if your passing a note ID and picking up that document from the agent, you will not get any unsaved changes. The agent is getting the document with the values stored in the NotesDatabase object, not a back-end representation of a front-end NotesUIDocument. This means if you’re wanting to take into account changes the user has made when running your agent, it’s really a PostSave event.
If your agent does detailed validation in lotusscript and you want this to trigger pre-save, then you have to re-write it in LotusScript or get creative. Off the top of my head, it might be possible to create a temporary document in server-side javascript with the values you need, save that, submit that in a hidden panel and return any success or failure message. That’s a bit crude, but I’m sure the principle could be refined into something more sophisticated and possible a reusable custom control of its own.
Regards
Paul
Subject: Re problem run lotusscript agent from xpage
(1) Domino.document1 is the name of the xpage data srouce (by default). (2) Now I understand the lotuscript agent will not able to work on unsaved data other than postSaveDocument event.
Thank again for you time and responses to my questions.