DocumentationStudioFormula Editor

Formula Editor

The Formula Editor is where you enter the value of a rule action. It has two modes:

  • Basic: pick a recipe and fill in the fields. No typing of formulas.
  • Advanced: write the formula yourself, including multi-step programs.

The editor opens in Basic when the formula fits one recipe, or when the field is empty. It opens in Advanced when the formula is more complex.


Open the editor

In a rule, the Value (or Formula) field is read-only. Click the field, or the expand icon next to it, to open the editor.

  • The title line shows where you are, for example Rule “Total salary” · THEN · sets TotalSalary.
  • The editor sits inside the working area. The Full screen button makes it fill the window.
  • Save puts the formula into the rule action and closes the editor. Cancel and Close leave without changing the action. The rule itself is saved with Save on the rule page.

Basic mode

  1. Under Choose a recipe, search for a recipe or pick a category.
  2. Fill in the numbered fields. A variable field has a list of variables and New, which creates a variable on the spot.
  3. Read GENERATED FORMULA and the Live preview. Click Run to try the recipe on sample values.
  4. Click Save.

If a field that is marked in red is empty, Save does not close the editor and shows Fill in the fields marked in red to save.

Choosing Replace text, binding a variable, trying an example and running the preview

The Basic builder with its parts numbered 1 to 5

  1. Back to recipes: return to the list. The formula the editor opened with is kept.
  2. The fields of the recipe.
  3. Examples to try: click Use to fill in the fields with an example. Related recipes switches to a similar recipe.
  4. Run runs the preview. The test values are only used for the preview and are never saved.
  5. GENERATED FORMULA: the formula the recipe makes. How this works shows the inputs and the same formula as you would write it in Advanced. Open this in Advanced moves the formula to Advanced.

Recipes

The recipe list for Tables and lists

CategoryRecipes
TextMake uppercase / lowercase / title case, Trim leading & trailing spaces, Replace text, Take part of a text, Get text length, Combine values, Insert Text Library content
NumberFormat a number, Add up a column, Average a column, Smallest value in a column, Largest value in a column
DateToday’s date, Add days to a date, Add months to a date, Add years to a date, Difference between two dates, Format a date, Start of month, End of month
Tables & listsCount rows, Combine a column’s values, Build a list from a column, Build a list with a template, Filter rows by condition, Find a row by ID, Find a row and read a field, Find a row and follow its reference, Find a row by field value, Get all rows from a list, Find rows matching conditions
Advanced & otherBuild a JSON object, Build a data table, Flatten nested arrays, Just a variable, A literal value

Use Just a variable to copy a variable, and A literal value for a fixed text or number. Text that is not meant to be evaluated is stored in quotes.


Advanced mode

Advanced shows the formula as text. Use it for formulas that combine several functions and for multi-step formulas.

The Advanced mode with its parts numbered 1 to 5

  1. Formula: the editor. Functions, variables and text have different colours.
  2. Format tidies the formula. The shortcut is Ctrl+Shift+F.
  3. Test Values and Run: enter a sample value for each variable in the formula and run it. Result shows the value. Error shows what went wrong.
  4. Variables: click a variable to insert it, or type {{ in the editor. New creates a variable.
  5. Functions: click a function to insert it. The filters All, Text, Number, Date and Table narrow the list.

Type the name of a function to open its reference. The reference shows the syntax, the arguments and examples. Load example puts an example in the editor and fills in its test values. Sample data shows the data an example uses, and Insert as variables creates those variables in your form when they do not exist yet.

Problems in the formula

The editor checks the formula as you type. A box such as 2 Issues Found lists each problem with its kind: Unknown function, Unknown variable or Syntax error.

The Issues Found list with an unknown function and an unknown variable


Switch between the modes

  • From Basic to Advanced always works. The formula moves with you.
  • From Advanced to Basic works only when the formula fits one recipe. Otherwise Basic is greyed out.

Basic greyed out for a multi-step formula


Multi-step formulas

In Advanced, a formula can have several steps: declare values, make decisions and loop over a table. Basic cannot show these.

A multi-step formula that adds up the salaries of a table, with the result

PartExample
Declare a valuelet total = 0;
Decideif (total > 100) { ... } else { ... }
Loop over a listfor (let row of {{Employees}}) { ... }
Loop with a counterfor (...) { ... } and while (...) { ... }
Return a resultreturn total;
Read a partrow.salary and list[0]
Comments// a line and /* a block */

Operators: +, -, *, /, %, ==, !=, <, <=, >, >=, &&, || and !.

The functions from Data Transformation functions work inside a program, and a {{variable}} reads a variable.

Join a name

let first = TextFormat({{firstName}}, "title");
let last = TextFormat({{lastName}}, "title");
return first + " " + last;

With firstName = "ada" and lastName = "lovelace" the result is Ada Lovelace.

Add up a column

let sum = 0;
for (let r of {{items}}) { sum = sum + r.amount; }
return sum;

With amounts 10, 5 and 7 the result is 22.

Choose a result

let n = TextLen({{firstName}});
if (n > 2) { return "long"; } else { return "short"; }

If the last statement is an expression without return, its value is the result, for example let x = 2; x * 21 gives 42.

Limits

A program is stopped when it goes beyond these limits, so a mistake cannot stall the form:

LimitValue
Loop iterations10,000
Steps1,000,000
Nested calls64
Run time1 second
Length of a text1,000,000 characters
Items in a list100,000

Variables in formulas

  • {{name}} reads a variable. A dotted path such as {{customer.address.city}} reads a value in the incoming data. Such a path is listed as a shadow variable. See the Test Runner.
  • Create variables on the Variables tab, or with New in the editor.