How to sum the values in numeric field objects

LiveCycle Designer customers often want to add simple calculations to a form, like calculating the sum of the values in two or more numeric field objects.

The following example shows how to write a script that calculates the sum of numeric field objects using FormCalc.

To perform calculations, FormCalc needs to know what objects in the form to include in the calculation. As a result, you need to name the Numeric Field objects that you want to sum on the Binding tab. Once you’ve named the numeric field objects, you can write a simple script using the field names, so that FormCalc knows exactly which fields to sum.

For example, if you have a numeric field object called grandTotal in which you want to display the sum of four other numeric field objects called total, stateTax, federalTax and shippingCharges, the FormCalc script you apply to the grandTotal numeric field object would look like this:

sum (total, stateTax, federalTax, shippingCharge)

Here is a summary of the steps involved:

1. Add the numeric field objects to the form.
2. Name each numeric field object in the Name box on the Binding tab.
3. Select the numeric field object that you want to calculate the sum. For example, “grandTotal”
4. In the Show list in the Script editor, select Calculate.
5. In the Language list,select FormCalc .
6. Add the “sum” script shown above to the Script Editor.
7. Preview and test the form.

To learn more about writing simple scripts to make calculations, have a look at the tutorial called Creating a Purchase Order Form located here.

LiveCycle Designer also includes a sample form snippet called Calculate the Field Sum (CalculateSum.xdp), which demonstrates how to calculate sums of fields that are at different levels in the form hierarchy. Form Snippets are installed in the EN\Samples\Form Snippets folder under the Adobe LiveCycle Designer installation folder. The topic Calculating the field sums in the Designer Help (Creating Calculations and Scripts > Examples of Common Scripting Tasks) also demonstrates how to calculate the sums of fields located at different levels of the form hierarchy.

VN:F [1.9.22_1171]
How to sum the values in numeric field objects, 8.1 out of 10 based on 31 ratings

9 Responses to How to sum the values in numeric field objects

1. Todd S. says:

I appreciate the information. I just started using LiveCycle and love it, although wish I could afford the full version.

Anyway, I am looking to create a table that converts military time into number of hours. Example: 07:00 to 17:00 = 10 hours. I see that Live Cycle ES2 will not import calculations (I created a functional table Excel) – is there a work around? Anyway, I need a distributable and fillable pdf file as a Work Service form for my field technicians to complete and return. I have created the fillable form – just need a workable table. Thank you.

2. Drew says:

Hi Tod,

You can write a script for this using JavaScript. Although, I don’t have the script to give you, you can probably find something on the web. Search for an example of JavaScript that calculates the difference between two times.

• Todd S. says:

Hello Drew, thank you for the interest – I continue to scour the web. Wish me luck.

3. Drew says:

You bet Tod. All the best.

4. Stefan says:

Hi,

I was wondering if it would be possible to add a number to the total? For example, when a user checks off a checkbox, I would like the specified price to add to the total retail value. Is this possible? Thanks!

Stefan

5. simon says:

i want to add 3 boxes and that script i know. i then want to (in another box) display the same total but give it a ceiling of \$50. i.e its for an expenses form that if you go over a set limit you only get the max. =IF(A4>=A5,A5,A4) is for excel but for livecycle????

6. Joolz says:

Hi. I am trying to sum total 11 totals, but the script editor refuses to recognise the first of the items, regardless of what the item is.
I have used the formula “sum (riesCell6, semCell6, vermCell6, frizzCell6, shCell6, clemCell6, cabmatCell6, sgCell6, bbCell6, ssbCell6, scsCell6)” which is what I have name each cell in the binding tab.
What am I missing?

7. Joolz says:

Smee again. I have now changed the individually named totals all to ‘Total’ in the Binding Tab, and reset the calculation to “Sum(Total[*].rawValue)” . The problem now is that the Binding Tab names are not changing the number in the grey area to denote each different label of the same name. Help!
Is anybody out there?

8. Tricky says:

Joolz,

I’m having the same problem. Did you figure out how to make it work?