cardinal

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 > 100000

Where you write them

Field or keyExample
depends_on, mandatory_depends_on, read_only_depends_ondoc.is_company
Row rules in RecType YAMLdoc.owner == user
Workflow transition Conditiondoc.days <= 5
Notification, Webhook and Assignment Rule conditionsdoc.priority == "Urgent"
Record Naming Rule Conditiondoc.customer_group == "Retail"
Automation Condition stepsdoc.source == "Website"

Syntax

KindForms
ValuesNumbers, "text" or 'text', true, false, null, ["A", "B"]
Namesdoc.<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
Choiceif doc.qty > 0 then doc.rate else 0

Functions

FunctionReturns
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_group or !doc.is_group, not doc.is_group == 1.
  • Write doc.status, not a bare status, and drop any eval: prefix.
  • Use &&, || and !. The words and, or and not are refused.
  • Math is exact. 0.1 + 0.2 == 0.3 is 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.

MeaningExpressionTemplate
and, or, nota && b, a || b, !aa and b, a or b, not a
In a list["A", "B"].includes(x)x in ["A", "B"]

On this page