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



Feb 24, 2013, 3:33 PM
47 Posts
topic has been resolvedResolved

return a value from a response to the parent

  • Category: Other
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags: Response Docs
  • Replies: 3

I have an XPage which contains an embedded view for response documents.  In this view there is a column which contains an "amount" field for the response.

I would like to create a computed field "grand total" on the parent to hold the total for all the amount fields of its responses. 
It has to be updated if an amount in a response is modified so the grand total reflected the update value.

How can I do this?

Feb 24, 2013, 9:42 PM
47 Posts
Re: return a value from a response to the parent
I found a solution, maybe it is not perfect but it is working :-)
 

var doc:NotesDocument = currentDocument.getDocument();

gt = 0;

var n = 0;

var dc = doc.getResponses();

n = doc.getResponses().getCount();

if (n > 0) {

var rep:NotesDocument = dc.getFirstDocument();

while (rep != null){

var amount = rep.getItemValueDouble('lineTotal');

gt = gt + amount;

rep = dc.getNextDocument(rep);

}

return gt;

}

 
Feb 25, 2013, 2:11 PM
586 Posts
Re: return a value from a response to the parent
 Danyele,
 
Be advised that you're not recycling your document object "rep".  This will cause a memory leak and might possibly crash your server eventually.  There's an example on the XPages Cheatsheet.
 
I would also recommend moving this code to a function in a Server JavaScript Library.  Pass the doc in as a parameter.  It's a good practice to use. 
 
Just some thoughts. 
Feb 25, 2013, 3:20 PM
47 Posts
Re: return a value from a response to the parent
Thanks for the advice :-)

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