Copy link to clipboard
Copied
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:
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
Have you opened the JavaScript console to see if there is any error in your script?
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
event.target.page can be used to access the page number of the field that is calculating.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now