This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Aug 3, 2016, 10:11 PM
7 Posts
topic has been resolvedResolved

Xpage postSaveDocument agent blank noteid

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 9.0.1
  • Role: Developer
  • Tags: xpage agent
  • Replies: 5

I ended up using the following code in the PostSaveDocument.

Using the currentDocument.getNoteID() was the ticket.  Not sure why the other methods didn't work though.

ag = database.getAgent("(agBarrierWebXpage)"); 

var noteid = currentDocument.getNoteID() //Nbarrier.getNoteID();

ag.run(noteid);

 

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

Aug 5, 2016, 5:09 PM
7 Posts
Xpage postSaveDocument agent blank noteid

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

Aug 7, 2016, 2:19 AM
586 Posts
hmm

It's hard to tell for sue... but a couple thoughts...

ag = database.getAgent("(agBarrierWebXpage)"); 

var noteid = currentDocument.getNoteID() //Nbarrier.getNoteID();

ag.run(noteid);

First of all...  on the first line you are missing the "var" in front of the ag.  NEVER forget the var.  It will ruin your day. Trust me.  Been there done that.  All variables in SSJS need to be created via a "var".

The error is giving you good information...  something is null.... it's either the "ag" because of the missing var...  or the noteid.  I kinda suspect it's the ag but that's just a guess.

I've never used "currentDocument".  I don't like it personally.  You should get your NoteId from your named dataSource in my opinion.  I don't have the editor in front of me...  it sounds like you tried but it didn't work.  You should post the code...

Know this though...  the named DataSource is likely an XSPDocument... which is not the same as a familiar "Back End Document".  So you might need to do.. 

myDataSource.getDocument().getNoteId()...  something like that...

 

Finally.. 

I don't know what this agent does.. but I STRONGLY recommend you stop calling agents.  Convert the LotusScript code to a SSJS function.  It's better for performance and it's better for you as a developer.

Hope something here helps.

Good Luck!

Dave

NotesIn9.com
 

 

 

 

Aug 8, 2016, 3:49 PM
453 Posts
I'm with David

If in doubt print something to the server console. During development I do a lot of that. I think that as Dave points out it is probably the var statement. 

I have a fair bit of LotusScript code that I run as background agent, and that works well,however, I never use them to return information. Write a SSJS code or a Java auction. 

The other day I was doing some experimenting on some SSJS code I have been using to open a document in a custom control. I was passing a form name and I had to relate it to a control to open. In my test I got the start time in milliseconds and the time from the before page loads. This process took about 75 milliseconds. I created a viewscope java bean (I do everything from a single XPage so l'm almost always in the same view). Now that same process take 6 milliseconds! Now the 75 milliseconds load time is hardly noticeable but it clearly demonstrate the concept. From LS to SSJS would no doubt be significantly faster, then to Java a further step up.

FWIW. 

Aug 8, 2016, 5:06 PM
298 Posts
Use the Debug Toolbar
The debug toolbar lets you print messages to a toolbar on top of your XPage, inspect scoped variables, view the components on a page and their methods, and more.

Bill, it can even do timing (there is an option to show the times in ms).

https://www.openntf.org/main.nsf/project.xsp?r=project/XPage%20Debug%20Toolbar

When I develop it is the first thing added to the design and I don't turn it off until I start acceptence testing.

Howard
Aug 8, 2016, 10:44 PM
453 Posts
Use the debug tool bar all the time.

Didn't realize that there was a timer. Will need to check that out. Checking scope variable is an invaluable feature. 


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal