Skip to content

Automation

Validation rules

A validation rule checks a record when it is saved and shows clear messages next to the right fields. Learn how to write checks, errors, and warnings.

A validation rule checks the data in a record when it is saved and tells the person exactly what is wrong. Use it when the record's own values decide whether a save is acceptable: an end date after the start date, a quantity above zero, a discount within a limit.

One validation rule can hold several checks. Each failing check shows its own message, attached to its own field. So people see every problem at once, instead of fixing one and hitting the next.

Errors and warnings#

Each check has a Severity:

  • Error — refuses the write. The record isn't saved. The person sees the message and fixes the field.
  • Warning — lets the write through. The record is saved and the person sees the message as a heads-up.

Use warnings for things worth a second look, such as a price far below the usual, and errors for things that must never be stored.

Create a validation rule#

  1. Open any view on the table, click Settings, choose Business Rules, and click New rule.
  2. Enter a Name and set the Rule type to Validation.
  3. Choose when it runs under Runs on, usually Create and Update.
  4. Optionally add conditions under When, for example only checking orders whose status is not "Draft".
  5. Under Checks, click Add a check and fill it in:
    • Name: a short label for the check.
    • Field this is about: the field the message is shown next to, or No particular field.
    • Severity: error or warning.
    • Passes when: the condition that describes valid data.
    • Message when it fails: what the person reads.
  6. Add more checks as needed, then click Create rule.
Warning: Passes when describes what valid data looks like, not what is wrong. To require a quantity above zero, write "Quantity is more than 0". The message is shown when that condition is false.

Examples#

RuleCheck passes whenMessage when it fails
End date after startEnd date is more than Start dateEnd date must be after the start date.
Positive quantityQuantity is more than 0Quantity must be greater than zero.
Discount limitDiscount is at most 20Discounts above 20% need approval.
Customer is activeRows exist in Customers where the customer is activeThis customer is no longer active.

Validation or guard#

Use a validation when the content of the record is wrong and the person can fix it by changing a field. Use a guard when the change itself isn't allowed, such as editing an approved order, whatever the values are.

Validations run after computations, so they see fields that computations filled in.

Stuck, or found something missing? Ask the community.

Ask the community

View as MarkdownSuggest an improvement