Function Reference

View as Markdown

Beyond arithmetic and comparisons, an expression can call functions to do more: count a list, check whether text contains a word, keep only the items that match a rule, or format a phone number. This page lists the functions commonly available. The builder also offers a function picker, which is the authoritative, up-to-date list while you are editing an expression.

Functions come in two flavors. Standard functions are the general-purpose tools that come with the expression language. Custom functions are extras built specifically for Gail workflows, like formatting a phone number.

How functions are written

A function name is followed by its inputs in parentheses. Some functions are written after the value they act on, joined by a dot, which reads naturally:

size(node.items.list)
"hello world".contains("world")

Function names use camelCase (for example startsWith, endsWith), while the values you reference use lowercase names with underscores (for example node.contact_phone). The two styles sit together cleanly, so normalizePhoneNumber(node.contact_phone) reads without confusion.

Standard functions

A selection of the general-purpose functions you will reach for most often:

FunctionWhat it doesExample
sizeCounts the items in a list, or the characters in textsize(node.contacts.list)
containsChecks whether text contains a smaller piece of textnode.subject.value.contains("urgent")
startsWithChecks whether text begins with a given piecenode.code.value.startsWith("POL-")
endsWithChecks whether text ends with a given piecenode.file.name.endsWith(".pdf")
matchesChecks whether text fits a patternnode.email.value.matches(".+@.+")
mapBuilds a new list by transforming each itemnode.quotes.list.map(q, q.premium)
filterKeeps only the items that pass a testnode.amounts.list.filter(n, n > 0)
intTurns a value into a whole numberint(node.count.value)
stringTurns a value into textstring(node.total.value)

With map and filter, the first name in the parentheses (like q or n) stands for the current item as the function walks the list.

[1, 2, 3, 4].filter(n, n % 2 == 0) // keeps 2 and 4

Custom functions

normalizePhoneNumber

Formats a phone number into the standard international format (like +442083661177). Give it the number and a two-letter country code so it knows how to read a local number.

normalizePhoneNumber("020 8366 1177", "GB") // "+442083661177"

This is handy for tidying up phone numbers before you store them or pass them to a call or messaging step, so they are all in a consistent shape.

If a function is given something it cannot handle, such as a phone number it cannot make sense of, the expression fails and the run stops with an error. Feed functions values you expect to be valid, and use a Conditional or Check earlier if you need to guard against bad input.