Skip to content

Formulas

A Number field can be a formula that performs a calculation. Formulas can reference other Number fields. Formulas are configured in the default or static value for a Number field.

  • Operators: +, -, *, /, %, ^, |, &
  • Functions: MIN, MAX, SUM, ROUND, ROUNDDOWN, ROUNDUP
  • All functions from Ruby’s Math module, including SIN, COS, TAN, etc.

Formulas use the following syntax for referencing field names:

  • Object keys are separated by a period (foo.bar)
  • Array indices are wrapped with square brackets (foo[0])

The following table shows how to convert between the JSON Pointer syntax, and formula references:

JSON PointerFormula Field Name
foo/barfoo.bar
foo/0/barfoo[0].bar
foo/bar/0foo.bar[0]

You may want to split up a calculation into multiple steps, or re-use the result of one calculation in multiple places. You can do this by creating a Number field that is both Static and Hidden.

This field will function as an intermediate “variable” that can be referenced by other formulas, but it will not be part of the API schema, and it is not displayed on the PDF.

Here’s an example template that demonstrates a number of different features.

Formula Example 1

Field NameRequired?Static?Default or Static value
aYesNo-
b/0YesNo-
b/1YesNo-
cNoNomax(b)
dNoYessum(a, b, c)
  • a and b are both required fields.
  • b must be an array that contains two numbers.
  • If c is not provided, the default formula will calculate the maximum value from the b array.
  • d is a static field, and can only be computed from the other fields. d is not part of the API.

Given the following values:

  • a => 7
  • b => [12, 15]
  • c => null

The generated PDF will show the following results:

Formula Example 2