Skip to main content
Variable expressions let you calculate or reshape a value when a component runs, instead of using a fixed value. For example, you can round a number, remove a file extension, or choose between two values based on a condition. To use an expression, write standard JavaScript inside the ${} notation in a component property, and refer to variables by name. For example, if file_name is a text variable, ${file_name.toUpperCase()} returns the file name in upper case. Maia evaluates the expression when the component runs and uses the result as the property value. To save a computed value for later components, use the Update Scalar component to set a variable to the result of an expression.

Where expressions work

  • Expressions work in string, number, and drop-down properties that accept variables. They aren’t accepted in drop-down properties that don’t accept variables.
  • A variable’s Default value isn’t evaluated. For example, a default of ${new Date().toISOString().slice(0, 10)} stays as literal text. To set a computed value, use an Update Scalar component at the start of the pipeline.
  • If an expression in an Update Scalar component fails, the variable can keep its previous value without raising an error. Use a Print Variables component to check the result.

Examples

In these examples, x and y are number variables, and name, path, and list are text variables.

Arithmetic

Arithmetic can return floating-point rounding errors. For example, -12.7 % 2 returns -0.6999999999999993. To avoid this, round the result, such as with ${Math.round((x % 2) * 10) / 10}.

Strings

Dates

toISOString() returns the date and time in Coordinated Universal Time (UTC). The getFullYear(), getMonth(), getDate(), and getDay() methods use the local time zone of the Maia runner, so near midnight they can return a different day from toISOString().

Yes/no checks

A yes/no check returns the text true or false, not a Boolean value. Store the result in a Text variable, and compare it against the text value in later components.

Simple choices

Lists

Use these expressions with a text variable that contains comma-separated values.