Skip to Content
Calculations and scriptsThe three kinds of script

The three kinds of script

Every field has a slot for each. Most fields use none; a few use one.

Value — works out the answer

Whatever the script returns is written into the field.

// Hours run this shift value('reading_end') - value('reading_start')

A value script re-runs whenever a field it reads changes. If the field is read-only, the script owns the value outright. If it is not, the script fills the field in and the person can type over the top — see Values people can overwrite.

Condition — decides whether the field appears

Return something truthy and the field is shown; return something falsy and it is hidden.

// Only ask about the fault when one was reported value('fault_reported') === true

If a condition script fails to run, the field stays visible. Hiding it would quietly remove a question from the form because of a typo, and a question nobody sees is a question nobody answers.

A hidden field still carries whatever value it had. Clear it in a value script if a stale answer would matter.

Validation — checks the answer

Return true when the answer is acceptable. Return a string to reject it, and that string is shown to the person as the error. Returning false gives a generic message, so a string is almost always better.

// Explain the problem, don't just refuse value('reading_end') > value('reading_start') ? true : 'The closing reading must be higher than the opening one.'

Validation runs on submit and, on the web, as the field changes. A record cannot be submitted while any validation script returns a message.

Reading the form

The three functions used in almost every script:

value('key')another field’s answer. Every field is also callable by its own key — reading_end() — unless the key collides with a function name.
rows('section')a repeatable section’s rows, as an array of objects
parent('key')an answer on the enclosing record, inside a repeatable row or a subform entry

The full list is in the script function reference.