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.
Esta página aún no se ha traducido. Estás leyendo el original.
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#
- Open any view on the table, click Settings, choose Business Rules, and click New rule.
- Enter a Name and set the Rule type to Validation.
- Choose when it runs under Runs on, usually Create and Update.
- Optionally add conditions under When, for example only checking orders whose status is not "Draft".
- 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.
- Add more checks as needed, then click Create rule.
Examples#
| Rule | Check passes when | Message when it fails |
|---|---|---|
| End date after start | End date is more than Start date | End date must be after the start date. |
| Positive quantity | Quantity is more than 0 | Quantity must be greater than zero. |
| Discount limit | Discount is at most 20 | Discounts above 20% need approval. |
| Customer is active | Rows exist in Customers where the customer is active | This 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.
Debates sobre esta página
¿Te has atascado o echas algo en falta? Pregunta a la comunidad.