Expression Builder

Use the Expression Builder to build string, mathematical, logical, and other expressions.

This page is organized as follows.

  1. Opening the Expression Builder

  2. Using the Expression Builder

  3. Expression Builder Functions

Opening the Expression Builder

Fields with a pencil icon inside have access to the Expression Builder.

Click the pencil to open the Expression Builder.

Using the Expression Builder

1. Select a function

Functions are organized by type as follows.

  • String

  • Mathematical

  • Logical

  • Premium

  • JSON

  • Other

Type the function name to filter the list of functions to the name you type.

2. Fill in the function fields

The fields to the right of the function depend on the function selected. Fill in the fields as appropriate.

To enter a variable, type two open curly brackets {{ and select from the list.

If you need more screen real estate, click the edit button to the right of the field.

To evaluate an expression, press the arrow to the right of the expression. If the expression includes variables, you are prompted to enter a temporary value for each variable.

3. Build complex expressions

To use an earlier expression as input, type two open curly brackets {{ and select from the expressions presented.

The selected expression is the last to be evaluated.

Renaming Expressions

As you build complex expressions, you may want to rename each expression to something meaningful.

Click the Expression field to rename the expression. The expression name must begin with the characters expr. The name cannot contain spaces and other special characters. Underscore characters are allowed.

When you rename the expression, Studio automatically renames all the places that call the expression.

Copy Expression List

Copy the contents of the Expression Builder and paste in another instance. For example, you may want to copy expressions from one variable value to another.

  1. Complete at least one expression in the Expression Builder.

    The Expression Builder copy expression list button is now visible.

  2. Click the Expression Builder copy expression list button.

  3. The Expression Builder paste/replace expression list button is visible since an expression is ready to paste.

  4. Open another instance of the Expression Builder.

  5. Click the Expression Builder paste/replace expression list button.

    The copied expression is pasted into this instance of the Expression Builder and replaces all preexisting expressions in the instance.

Note:

An undo button displays briefly following the paste/replace action.

Clear all Content

Return to the place in the user interface where you opened the expression builder. Hover over the form field. If an expression exists for this field, the "x" symbol displays. Click the "x" symbol to clear all content from the expression.

Expression Builder Functions

String Operations

String function operations work only with English language characters.

Function

Description

Text Input

Enter a text string.

Get String Length Returns the length of the string in characters.
Convert to Uppercase

Converts all alphabetic characters to uppercase. Other characters like punctuation, numeric, and umlaut-a (ä) do not change.

Convert to Lowercase

Converts all alphabetic characters to lowercase. Other characters like punctuation, numeric, and umlaut-a (ä) do not change.

Trim String

Strips white space from the beginning and end of a string.

By default, Studio strips tabs, new lines, carriage returns, null bytes, and vertical tabs. You can customize this list.

Trim String from End

Strips white space from the end of a string.

Trim String from Start

Strips white space from the start of a string.

Get sub-string

Returns the portion of value specified by the index and length parameters.

Parameters

Description

Text Return a portion of this string.
Start Index

If the index is non-negative, the returned string starts at the indexed position counting from zero.

If the index is negative, the returned string starts at the indexed position from the end of the string.

Length

If the length is positive, the string returned contains at most that number of characters.

If the length is omitted, the substring from the index til the end of the string is returned.

If the length is negative, the given number of characters are omitted from the end of the string.

Replace String

Replaces all occurrences of the search string with a new string. Select if the search is to be case sensitive.

Search String

Returns the position of the search string within the subject string. Select if the search is to be case sensitive.

Extract Email from String

Extracts the first email address found in the string.

Extract Number (fixed) from String

Extracts the first sequence of digits found in the string of a given fixed length. The length can be entered as an expression.

Extract Number (min-max) from String

Extracts the first sequence of digits found in the string with at least the minimum number of digits and no more than the maximum number of digits. The lengths can be entered as expressions.

Extract Letter (fixed) from String

Extracts the first sequence of alphabetic characters found in the string of a given fixed length. The length can be entered as an expression.

Extract Letter (min-max) from String

Extracts the first sequence of alphabetic characters found in the string with at least the minimum number of characters and no more than the maximum number of characters. The lengths can be entered as expressions.

Custom Regex

Extracts the first match or first matched group according to the regular expression. Access regular expression flags by clicking /im.

Left Pad String with a Character

Adds left padding to a string. Provide the padding character, which can be any single character, and the new length of the string. If you enter multiple padding characters you will see HTTP error code 422 unprocessable entity. Enter a positive integer for the length.

Right Pad String with a Character

Adds right padding to a string. Provide the padding character, which can be any single character, and the new length of the string. If you enter multiple padding characters you will see HTTP error code 422 unprocessable entity. Enter a positive integer for the length.

Math Operations

Math operations always return a number.

You can supply all input numerical values as variables.

If you omit an input value or supply a nonnumerical value where a numerical value is expected, Studio converts the value to 0.

Function

Description

Round

Round the number according to the given precision.

Floor

Round the number down to the nearest integer.

Ceil

Round the number up to the nearest integer.

Math Operations

Add, subtract, multiply, or divide two numbers.

The modulo operator is also available and converts both operands to integers before calculating the remainder.

Random Number

Return a random integer between and inclusive of the two numbers you supply in the minimum and maximum value fields.

Logical Operations

Where the input type is boolean, enter values as follows.

Boolean

Numeric

String

True 1

Any string other than those translating to false.

False

0

"false" (case insensitive)

Empty string

Logical functions are as follows.

Function

Description

Boolean Input

Return Boolean true or false.

Compare

Return the Boolean evaluated comparison of two values. Treat the input as numeric, text, or Boolean.

Conditions (AND/OR)

Return the Boolean evaluated result of (condition1 AND condition2) or (condition1 OR condition2).

Matches Regex

Search text for a regular expression. Return the Boolean evaluated result. Access regular expression flags by clicking /im.

Ternary

Use similar to the php ternary operator to streamline if/then/else statements.

The function takes three parameters.

Parameter

Description

if Enter the condition that evaluates to true or false.
then Enter the code to evaluate when the condition is true.
else Enter the code to evaluate when the condition is false.

Premium Operations

Use the Get Number function to detect the type of phone used to traverse the call flow. You may want to run Get Number on logged date.

JavaScript Functions

Select from content items of type JavaScript in the Studio account. See Functions.

JavaScript functions returning a boolean value, return true or false.

JSON

See Evaluating JSON Objects and Arrays.

Date and Time Formats

The default date-time format is Y-m-d H:i:s.

All dates and times are at least two digits. For example, January 1st would be 01-01.

Special characters may also be added, but may affect text-to-speech.

Component

Format

Example

Description

Default Y-m-d H:i:s 2018-01-24 15:34:56  
Year Y 2018 Four digit year
  y 18 Two digit year

Month

M

Jan

Abbreviated name of the month

 

m

01

Abbreviated month number

Day

D

Wed

Abbreviated day of the week

 

d

01

Day of the month

 

S

th

Ordinal number suffix

Hour

H

15

Hour in 24-hour notation

 

h

03

Hour in 12-hour notation

Minute

i

34

Time in minutes

Second

s

55

Time in seconds

AM or PM

A

PM

AM or PM in capitals

 

a

pm

AM or PM in lower case

Time Zone

P

-05:00

Time zone based on account settings

Epoch Time

U

1516826095

Seconds since midnight Jan 1 1970 UTC

Punctuation

m/d/y

01/26/18

American date format with slashes

 

M ds, Y

Jan 24th, 2018

American date format with ordinal notation

 

h:i A

03:34 PM

Hours and minutes in 12 hour notation