Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Spawn Page Calculation Carry to next spawn page

New Here ,
May 03, 2016 May 03, 2016

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

TOPICS
Acrobat SDK and JavaScript , Windows
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2016 May 03, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 03, 2016 May 03, 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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2016 May 03, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 06, 2016 May 06, 2016

There is no error when i check the console. I actually think i may have figured out the problem. i miss interpret pageNum as getting what that the page number for that page in the document, when it seems it actually gets the current active page. That is why when every I spawn a new page, it carry over that the last page.

Anyone know what function will help catch the page number?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2016 May 07, 2016

event.target.page can be used to access the page number of the field that is calculating.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 07, 2016 May 07, 2016
LATEST

Since the page's form fields names on a p, ge spawned from a template not overlayed, you can take any one of these fields and get the "P#" and template values from the form field name. Split the form field name by the "." and the zero element of the resulting array will be the "P#" and the one element will be the template name.  This will also work for getting field names if a previously spawned template page has been deleted.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines