These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Help: Dynamic Table with Conditional Sum

jhawkes01
Registered: Oct 21 2010
Posts: 4

I have created a travel expense tracking form. I have used your dynamic table to give users the ability to enter all their travel reimbursements. There are many fields, but the important ones for this questions are: expense type, payment type, total (which calculates a total based on the original charge * conversion rates).
 
I also have a summary sheet (which is used by the controller’s office to process the reimbursement). The sheet needs to use IF statements to SUM values based on the their answers below. My current script works to conditionally sum the first row of the tracking expense chart; however, if I add additional rows, it will not evaluate those. I think I need some sort of array formula but I don’t know what that looks like. I have been using FormCalc because I know no JavaScript.
 
if (form1.#subform[3].General_Expense.Item[*].expense_type == “51807 – Membership Dues/Fees” and form1.#subform[3].General_Expense.Item[*].payment_type <> “BMC Credit Card”) then Sum(form1.#subform[3].General_Expense.Item.total) endif
 
Form can be emailed upon request.

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
What is the repeated subform? is it "item"? And I take it that this calculation is in a field outside of the table?

Given that, then you'll need to write a loop that applies this "if" statement for each individual repeated instance. This kind of complex logic is better implemented with JavaScript than FormCalc.

For example:
var sum = 0;
var aLines = form1.resolveNodes("$..General_Expense.Item[*]");
for(var i=0;i<aLines.length;i++)
{
   if(aLines.item[i].expense_type.rawValue == "51807 – Membership Dues/Fees"
      && aLines.item[i].payment_type.rawValue != "BMC Credit Card")
       sum += aLines.item[i].total.rawValue;
}
sum;



Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

jhawkes01
Registered: Oct 21 2010
Posts: 4
Thank you for the response. "item" is a body row in a table that repeats with when a user clicks an "add row" button. The calculation is outside of that table in a separate table and subform.

I knew you have to do some sort of loop or array, however, I don't know how to write the first part of my query in Javascript (IF conditional statements and SUM function) there for the JavaScript loop statement you so kindly provided doesn't really help. Can you either provide assistance on translating the rest of my query to Javascript or help write the loop in FormCalc?


thomp
Expert
Registered: Feb 15 2006
Posts: 4411
My mistake. There was an HTML character in the code. So it got cut off. It's not complete. take a look at my previous post

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

jhawkes01
Registered: Oct 21 2010
Posts: 4
Thank you for the updated code, I appreciate all your help. For some reason the boxes are not showing the sum.

Is there a way I can send you my form so you can look at it?

jhawkes01
Registered: Oct 21 2010
Posts: 4
I wanted to provide a link to this form:
http://www.brynmawr.edu/provost/documents/Travel_Form.pdf
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
That link is not working. You could try uploading it to Acrobat.com. But really, you need to do some debug. This is something you need to do yourself.

But there are lots of reasons why the script might not be working properly. For example, the script might be marked as FormCalc, there might be a syntax error(I just wrote it, I didn't test it), but most likely it's the SOM path in the resolveNodes function. It should be modified to be specific for your form.


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script