I have been following the xpages exercise below to get an agent to run after I save a document but it fails due to the noteid being blank. This page has two datasources on it, Qdocument which supplies static information from another database to the page and Nbarrier which is the new document that I'm creating and saving in the current database.
I have a save button on the page which executes the following code with a Full Update:
Code to return the user back to the view
viewStateBean.restoreState = true;
if (sessionScope.containsKey('lastView')) {
context.redirectToPage(sessionScope.get('lastView'));
} else {
context.redirectToPage("xpSurveySetup");
}
In the querySaveDocument I have some code to populate some fields in the new Nbarrier that get their values from sessionScope variables and computed fields on the form.
Nbarrier.setValue("BStandard", getComponent("FStandard").getValue());
Nbarrier.setValue("BFacilityNumber", getComponent("BFacilityNumber").getValue());
Nbarrier.setValue("BSite", sessionScope.get("facilityValue"));
Nbarrier.setValue("ProjNum", sessionScope.get("projectValue"));
In the postSaveDocument I have the following code to run the agent once the Nbarrier is saved. This code I pulled from the exercise example.
ag = database.getAgent("(agBarrierWebXpage)");
var noteid = Nbarrier.getNoteID();
ag.run(noteid);
When this code runs I get the following error message and haven't been able to figure why I get it.
Error source
Page Name:/xpBarrierNew.xsp
Control Id: button14
Property: onclick
Exception
Error while saving document
Error while executing JavaScript action expression
Script interpreter error, line=3, col=4: [TypeError] Exception occurred calling method NotesAgent.run(string) null
JavaScript code
1: ag = database.getAgent("(agBarrierWebXpage)");
2: var noteid = Nbarrier.getNoteID();
3: ag.run(noteid);
4:
5:
I have spent way too much time on this not to have it working. I have tried using the documentContext which several posts suggested and still failed to run agent. I have looked at this post and it didn't help.
https://www-10.lotus.com/ldd/ddwiki.nsf/dx/xpages-get-unid-of-created-xpage.htm
Any suggestions would be greatly appreciated. Mean while I'll be pounding my head on the desk hoping that I figure this out by accident haha.
Sample Code to run agent pulled from this post.
https://www-10.lotus.com/ldd/ddwiki.nsf/dx/Tutorial-Introduction-to-XPages-Exercise-20