Overview
A validation rule is a condition on a record. When it evaluates to false, Twenty rejects the record and shows the rule’s message.Validation rules are only enforced in workspaces where the feature is available.
defineValidationRule from twenty-sdk/define:
Writing expressions
ruleExpression provides:
field('name')reads a field, andfield('company.employees')reads a field through a many-to-one relation.nowis the current date and time.and,orandnotcombine conditions.eq,notEq,gt,gte,ltandltecompare values.add,subtract,multiplyanddividecompute values.isIn(field('stage'), ['NEW', 'WON'])checks a value against a list.- Functions such as
isNonEmptyStringandisDefined.
twenty app pull writes back. You can write that string directly:
and, or, not, ==, !=, <, <=, >, >=, +, -, *, / and in [...], not && or ||. Text goes in single or double quotes.
A rule can read fields you declare, and the system fields Twenty provisions, such as createdAt. The CLI checks expressions against your app’s own objects. On an object outside your app, it only checks the syntax and the server checks the fields at sync time.
Fields that become unavailable
A sync keeps an existing rule’s
isActive, so a rule a workspace admin turned off stays off. Only new rules start on.