Skip to main content

SmartFormulas

SmartFields give you the values in your flow. A SmartFormula turns those values into a computed number, dropped inline into any text field by wrapping it in [[ … ]]. AutoFlow evaluates the expression, formats the result, and substitutes the whole [[ … ]] block with the formatted number. (To ask a yes/no question instead, see SmartFilters.)

The general shape is:

[[expression]]
[[expression;format]]

The optional ;format clause picks a specific Business Central format string. Leave it off (or write a bare ;) and you get the default rendering – AutoFlow uses <Standard Format,9> under the hood, which is locale-neutral (decimal point, no thousand separators).

Operators

OperatorDoesExample
+add[[2 + 3;]]5
-subtract[[10 - 4;]]6
*multiply[[{{order.total}} * 0.19;]]
/divide[[{{order.total}} / {{order.lines}};]]
%modulo (remainder)[[7 % 3;]]1
^power[[2 ^ 8;]]256
( )grouping[[(1 + 2) * 3;]]9

Functions

FunctionDoesExample
max(a, b)larger of two values[[max({{order.total}}, 100);]]
min(a, b)smaller of two values[[min({{quote}}, {{cap}});]]
abs(a)absolute value[[abs({{difference}});]]
round(value, decimals)round to N decimals (banker's)[[round({{order.total}} * 1.19, 2);]]
floor(value, decimals)round down to N decimals[[floor({{order.total}}, 0);]]
ceil(value, decimals)round up to N decimals[[ceil({{order.total}}, 0);]]

round, floor, and ceil take a decimals argument: 2 rounds to two decimals (12.34712.35), 0 rounds to whole numbers, negative values round to tens / hundreds (-2 → nearest hundred).

Aggregating a list

When a SmartField holds a list – the lines of a document, several records from a Find step – you can roll the whole list up into one number with an aggregate function:

FunctionDoes
sum(…)total of the values
avg(…)average of the values
min(…)smallest value
max(…)largest value
count(…)how many entries the list has

There are two shapes, depending on what the list contains:

A list of values. If the SmartField is already a list of numbers, pass it on its own:

[[sum({{invoice.lineAmounts}});]]

A list of records. If the SmartField is a list of records (a reference), give the list first and then the value on each row to add up:

[[sum({{invoice.lines}}, {{invoice.lines.amount}});]]

Here {{invoice.lines}} is the list to walk and {{invoice.lines.amount}} is the amount on each line. count only needs the list itself – [[count({{invoice.lines}});]].

The builder guides both cases: pick a list, and if it is a record list it opens a second picker scoped to that list so you can only choose a value that lives on its rows.

min and max do double duty – with a single list argument they aggregate the list, but with two plain numbers (min(2, 3)) they stay the smaller/larger-of-two functions from the table above. AutoFlow decides based on whether the first argument is a list.

The format string

The part after the ; is a standard BC format string – the same one you'd pass to Format(value, 0, '<format>') in AL. A few useful shapes:

FormatResult for 1234.5
(omitted or empty)1234.5
<Precision,2:2>1234.50
<Standard Format,0>1,234.5 (English) / 1.234,5 (German)
<Precision,2:2><Standard Format,0>1,234.50 (English) / 1.234,50 (German)

For most cases, leaving the format off ([[…]]) is fine – you get a locale-neutral decimal rendering (decimal point, no grouping). Reach for a format string only when you need precision control or your local number format.

Rendering in your local (regional) format

To show a number the way your BC session displays amounts – with your locale's thousand and decimal separators – add <Standard Format,0>. For example, in a German session:

Amount: [[{{order.total}};<Precision,2:2><Standard Format,0>]] EUR

turns a value of 38401.05 into 38.401,05. The <Standard Format,0> part is what switches to your local separators and grouping; put <Precision,2:2> in front of it to fix the number of decimals. A precision token on its own (<Precision,2:2>) stays locale-neutral.

Examples

The total with VAT is [[{{order.total}} * 1.19;]] EUR.

Plain inline calculation.

Net: [[{{order.total}};<Precision,2:2>]] EUR
Tax: [[round({{order.total}} * 0.19, 2);<Precision,2:2>]] EUR

Two formulas in one block of text, both formatted to two decimals.

Buffer days: [[max({{daysLeft}} - 2, 0);]]

Never go below zero.

Tips

  • Don't quote numbers. Formulas only see numbers – {{order.total}} resolves to the number, not to text. If a SmartField resolves to text that looks like a number, it works; if it resolves to non-numeric text, the formula breaks.
  • One formula = one number. If you need a calculation that depends on a yes/no decision, use a Decision step or a Parser step to pick the right value first, then drop the SmartField into the formula.
  • Use parentheses freely. Multiplication and division bind tighter than addition and subtraction, but parentheses are the easy way to be sure of the intent.

Where SmartFormulas show up

SmartFormulas can appear inline in any text-accepting field on a step configuration – descriptions, URLs, request bodies, parser inputs, error messages, and so on. Wherever a SmartField token ({{ … }}) is allowed, a SmartFormula block ([[ … ; ]]) is allowed too.