Expressions
The condition language used by depends_on, row rules, workflows, notifications and automations.
Conditions in Cardinal use one small JS-like language. The server and the desk run the same compiled code, so a depends_on rule hides a field in the browser exactly when the server would.
doc.status == "Open" && doc.grand_total > 100000Where you write them
| Field or key | Example |
|---|---|
depends_on, mandatory_depends_on, read_only_depends_on | doc.is_company |
| Row rules in RecType YAML | doc.owner == user |
| Workflow transition Condition | doc.days <= 5 |
| Notification, Webhook and Assignment Rule conditions | doc.priority == "Urgent" |
| Record Naming Rule Condition | doc.customer_group == "Retail" |
| Automation Condition steps | doc.source == "Website" |
Syntax
| Kind | Forms |
|---|---|
| Values | Numbers, "text" or 'text', true, false, null, ["A", "B"] |
| Names | doc.<field>, parent.<field> in a child row, user (the current user's name) |
| Compare | ==, !=, <, >, <=, >=. === and !== mean the same |
| Logic | &&, ||, !, parentheses |
| Math | + - * / on exact decimals. + also joins two strings |
| Lists | ["A", "B"].includes(doc.status), doc.items.length |
| Choice | if doc.qty > 0 then doc.rate else 0 |
Functions
| Function | Returns |
|---|---|
today(), now() | The date or time in the site's time zone |
is_set(x) | True when x has a value |
has_role("Sales Manager") | True when the user holds the role |
any(doc.items, row.qty > 100) | True when a child row matches |
min(a, b), max(a, b) | The smaller or larger value |
abs(x), floor(x), ceil(x), round(x, 2) | Rounding. round rounds ties to even |
date_diff(end, start) | Days between two dates |
add_days(d, n), add_months(d, n) | A date moved forward or back |
month_start(d), month_end(d) | The first or last day of the month |
Rules that differ from Frappe
- Comparisons are strict.
doc.qty == "5"on an Int field does not compile, because the two sides have different types. - A Check field is a boolean. Write
doc.is_groupor!doc.is_group, notdoc.is_group == 1. - Write
doc.status, not a barestatus, and drop anyeval:prefix. - Use
&&,||and!. The wordsand,orandnotare refused. - Math is exact.
0.1 + 0.2 == 0.3is true.
In a condition, null, "", 0, false and an empty table count as false. So doc.reason alone means "reason is set".
A save that holds a bad expression is refused with the position of the error and a hint, such as drop eval:.
Row rules have limits
Row rules turn into SQL, so they cannot use if ... then ... else or arithmetic. Workflow and automation conditions can.
Templates use Jinja
Print formats, Email Templates, notification messages and web pages are Jinja templates, not expressions. They keep Jinja's own words.
| Meaning | Expression | Template |
|---|---|---|
| and, or, not | a && b, a || b, !a | a and b, a or b, not a |
| In a list | ["A", "B"].includes(x) | x in ["A", "B"] |