Skip to main content
Participant
May 3, 2016
Question

Spawn Page Calculation Carry to next spawn page

  • May 3, 2016
  • 1 reply
  • 1302 views

Hi all!

I am trying to create a simply invoicing PDF that will spawn different the same invoice pages with a button and a summary page:

  • first page is a summary page that will sum up all the different expenses from the following invoice page
  • I create a template with that invoice page (it is only 1 page), and it is hidden.
  • there is a add page button that will spawn the invoice template page
  • there is a remove page button that will remove the last page (which stop at summary page).
  • Each field from spawn page will be name P#.Invoice.[FieldName]
  • When adding or removing a page, I added this.calculateNow(); to recalculate the numbers that might be change.

My problem is, for some reason, after creating the first invoice page, the different expense total for that previous page is carry over.

e.g. the 1st invoice page has service expense total $100. When I spawn the 2nd invoice page, that $100 will appear in that page's field.

this is what the script I wrote for that field, and other calculating fields, with small adjustment in which field to capture.

this.calculateNow();

var f_prefix = "";

f_prefix = "P" + (this.pageNum) + ".Invoice.";

event.value = this.getField(f_prefix+"HoursWorked01").value*100;

I guess my question is whether I am missing something from my script or I wrote something wrong.

Thanks in advance.

Message was edited by: Tom Lam

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
May 3, 2016

After spawning you should call the calculateNow command, as the spawn itself doesn't trigger a new calculation of the fields in the file, so the old values remain in the new fields.

Tom_Lam90Author
Participant
May 3, 2016

This is the script I have in the add page button. Issue persists.

var InvoiceTemplate = this.getTemplate("Invoice");

InvoiceTemplate.spawn(numPages,true,false);

this.calculateNow();

Inspiring
May 3, 2016

Have you opened the JavaScript console to see if there is any error in your script?