Expand my Community achievements bar.

Need Help Creating A Sub-Total Box On 3 Page Invoice

Avatar

Former Community Member
I have a 3 page Invoice with Grand Total on the last page that already totals all three pages together. No Problem here.



I copied & pasted a Sub-Total box from the Template Manager and attached it to the bottom of the first two invoice pages.



The problem is, the Sub-Total amounts continue to add the other page amounts. It's like I have three Grand Total boxes instead of two individual Sub-Total boxes.



Any help would be greatly appreciated!
10 Replies

Avatar

Former Community Member
Sorry for the delay in getting back to you ..... I was looking for a sample that I could provide.



The technique to use would be to get a list of all objects that are on the page that you want to create the subtotal on. Then with this reduced set of objects, search out the individual fields and add then together to make your total. In the example I have we created a function to do this and passed the object subtotal object itself to the function. The function then determines which page the object is on, gets all field objects from that page (in our case we are asking to add all fields called fldSavings), then cycles through each field and totals them and finally returns the sum back to the calling program. Hope this helps .... see the code below we call it in this way:



scoScript.getPageTotals(this.name);



Here is the function:



function getPageTotals(objFld){

var nPage = xfa.layout.absPage(objFld);

var oFields = xfa.layout.pageContent(nPage , "field");

var nFieldCount = oFields.length;

var numFldTotals = 0;



for (var nNodeCount = 0; nNodeCount < nFieldCount; nNodeCount++)

{

if (oFields.item(nNodeCount).name == "fldSavings")

{

numFldTotals = numFldTotals + oFields.item(nNodeCount).rawValue;

}

}

return numFldTotals;

}

Avatar

Former Community Member
Thank you Paul for your response and in depth detail in to my problem.



I have to apologize up front for my next set of questions due in large part to my ignorance in Script. The example you show seems very complex for a function that I though would be simple. But, I guess if the function I'm trying to use where that simple by default, I wouldn't be here searching for help. I thought I was simply overlooking putting a check mark in something or activating a box. But if this is the only way to get a Sub-Total box to work with a Grand Total Box on multiple pages, then there it is.



1.) Do I associate the first five lines of the Script to each of my three Sub-Total Boxes? If so, do enter it on the "initialize" line of the "Show" tool bar?



2.) Is the last three lines of the Script to be used with the "Grand Total Box" and in the same manner as in step One?



Thanks again for your patience.

Avatar

Former Community Member
The grand Totals are much easier because you are always dealing with the entire document and you can have them set to add all fields.



The subtotals become more complicated because you are only dealing with objects on a single page.



Before I can answer your other questions I have to know whether you are building an interactive form (where the user will enter values and the subtotals will change automatically) or are you merging data onto the form and using it as a print form (more like a report or a statement).

Avatar

Former Community Member
It's an interactive form. I send an 3 page invoice to a vendor with quantities and description already filled out. They enter the values only.



Currently, all I have is a Grand Total Box at the bottom of the third page and working on attaching Sub-Total Boxes to the first 2 pages.

Avatar

Former Community Member
First create a script Object and put this code in it:



function getPageTotals(objFld){

var nPage = xfa.layout.absPage(objFld);

var oFields = xfa.layout.pageContent(nPage , "field");

var nFieldCount = oFields.length;

var numFldTotals = 0;



for (var nNodeCount = 0; nNodeCount < nFieldCount; nNodeCount++) { if (oFields.item(nNodeCount).name == "fldSavings") { numFldTotals = numFldTotals + oFields.item(nNodeCount).rawValue; } } return numFldTotals; }



Next on the exit event of th eindividual fields you want to total put the code: scriptObjectName.getPageTotals(this.name);



Each time the user exits a field, the scriptobject will fire and the subtotal for that page will be calculated.

Avatar

Former Community Member
I don't know if I performed this operation correctly. Because the Sub-Total Box is still showing the Grand Total Amount.



I tried following your instructions above. Basically this is the steps I used. Maybe you can tell me what I'm doing wrong.



1.) I clicked my Sub-Total Box.

2.) Copied & Pasted your Script in the "Initialize" Toolbar w/JavaScript as Language.

3.) Copied & Pasted your Script in the "End" Toolbar w/JavaScript as Language.

4.) Went to PDF Preview and No Change.



Any suggestions?

Avatar

Former Community Member
You are correct - the operations were done incorrectly.



1. Create a new Script Object.



Go to the Hierarchy view, click on the Highest level node (typically form1). Right mouse click and choose "Insert Script Object". A new Variables node and untitled script object appears. Rename the script object to - myScriptObject.



2. Put code into the script object



Copy and paste the function from above into the script object. By clicking on the script object the script editor will display all code that is on that script object. Note that there are no events to choose (because you are creating a script object).



3. Call the script object from your subTotal Field.



On the exit event of the fields that you are totalling add the code subTotalFieldName.rawValue = myScriptObject(this.name);



Try this and if you cannot get it to work I suggest you give me your email address and I will have you mail the form back to me so I can do it for you then you can see what I mean.

Avatar

Former Community Member
Paul,

Thanks for the clear and understandable instructions.



Unfortunately, my Sub-Total Box is still showing the grand total amount.



I was able to follow your instructions to the letter.



I'm sorry but I don't understand why it's not functioning.



jldeci@hotmail.com