Posts tagged "sum the values in numeric fields"

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]
Was this helpful? Please rate the content.
Rating: 8.1/10 (31 votes cast)