Field Calculations
Last updated
Last updated
Field calculations allow form fields to have their display value calculated while the form is being filled. Typically this is done to calculate a price (or other number) based on the values which are entered in other fields. This calculated field value can then be used as the payment total when Paperwork is integrated with a payment provider.
Both the Label and Textbox form features support calculations. To set up a calculation, click on the Label or Textbox that you want to have a dynamic value, and in the configuration bar click the button with a sigma icon to open the Calculate Field Value dialog. You can then type a mathematical formula into the box which will be (re-)evaluated as the form is being filled out and the fields it depends on are changed.
The calculation formula supports all basic mathematical and logical operators. Below is a list of those which are most commonly used. There may be some supported operators missing from this list.
Addition
+
2 + 5
Subtraction
-
5 - 2
Multiplication
*
2 * 5
Division
/
5 / 2
Grouping / brackets
(
and )
2 * (5 + 3)
Less than
<
2 < 5
Less than or equal to
<=
2 <= 5
Greater than
>
5 > 2
Greater than or equal to
>=
5 >= 2
Equals
==
2 == 2
Not equals
!=
2 != 5
And (both must be true)
and
2 < 5 and 5 < 8
Or (either must be true)
or
5 < 2 or 5 < 8
Not (must not be true)
not
2 < 5 and not 5 > 8
Text literal
"
and "
"This is some text"
You can also use the Feature Name of other form fields as variables in the formula. This name can be found in the configuration bar when that field is selected, underneath Selected Feature. The current value present in that field will then be replaced into the formula when it is calculated.
Here's an example of how you might calculate the total price with tax included, based on the amounts present in other fields in the form:
There are a large number of functions built into field calculations which can be used to compute more complex operations. A function consists of a name followed by open and close parentheses. Inside the parentheses you add what are called arguments, separated by commas. Arguments are typically numbers, text literals, or the names of other form fields, but they can also be a mathematical calculation of their own, or even another function. Below is a list of some of the most commonly used functions and examples of how to use them.
Exponent / Power
pow(x, y)
pow(2, 5) == 32
Round down
floor(x)
floor(2.8) == 2
Round up
ceil(x)
ceil(2.1) == 3
Round to a fixed number of decimal places
fixed(x, y)
fixed(5.8888, 2) == 5.89
Absolute value
abs(x)
abs(-2) == 2
Concatenate text
concat(x, y, ...)
concat("Hello", " ", "World", "!") == "Hello-World!"
If the 1st argument is true, return the 2nd argument, otherwise return the 3rd argument.
if(x, y, z)
if (2 < 5, "Smaller!", "Bigger!") == "Smaller!"
Count the number of words in the text
wordCount(x)
wordCount(Description_Field_Name) == 140
date(x, "yyyy-mm-dd")
date(Date_Field_Name, "ddd mmm d") == "Tue Aug 9"
Get the time until the 1st argument. Calculated starting from the 2nd argument if supplied, otherwise starting from now.
secondsUntil(x, y)
minutesUntil(x, y)
hoursUntil(x, y)
daysUntil(x, y)
minutesUntil("2:08 pm", "2:00 pm") == 8
daysUntil(Future_Date_Field_Name) == 49
Transform a date/time (usually from a Date Chooser or Time Chooser field) into the requested format. See this page for a list of format options: .