From Bright Pattern Documentation
Jump to: navigation, search
• 5.3 • 5.8

Built-in Functions

A number of built-in functions may be used in the Scenario Builder application. This page describes such functions and provides examples of how to use them.

How to Invoke Functions

To invoke a function from a text field, prefix it with an equal sign. For example: =now("UTC")

Function Descriptions


Escapes the control characters or other special characters that occur within a JSON expression before adding JSON to another JSON as a text field. One way to use this function is to use a Set Variable block to JSON-escape each individual variable before including the variable in JSON.

Example 1

When using the function with string literal:

=escapeJSON('{"firstName":"John", "lastName":"Doe"}')

Example 2

When using the function with JSON variable (i.e., data received by the FetchURL block or Zendesk,, or other CRM Search blocks):


For example, if a FetchURL block received a JSON object that was stored in the variable varJSON the actual content looks like:

  "firstName": "John",
  "lastName": "Doe"

Applying the escapeJSON() function looks like:


And the result will be:


formatdatetime(int unixtimestamp, string format)


For example:



Converts duration in specified in seconds into MM:SS or HHH:MM:SS formats. It produces formatted string as output.

For example:

formatduration(121) will return "02:01"

hmac(hash_function, key, message)

Creates an authentication hash (HMAC) for MD5, SHA-1, and SHA-256, where Hash_function = (“MD5” | “SHA-1” | “SHA-256”). The returned value is a string with base64-encoded hash.


Returns the number of characters in a string.

now(string timezone)

Returns the current time in the specified time zone in Unix format (number of seconds elapsed since 1/1/1970, 00:00:00 UTC). Time zone is optional; if not specified, the current time will be returned in the tenant’s default time zone.

parsedatetime(string datetime, string format)

Returns the specified date and time in Unix format (i.e., number of seconds elapsed since 1/1/1970, 00:00:00 UTC). The date and time input is expected in the ICU’s Java SimpleDateFormat.


Inputs an integer parameter and returns a random integer in the configured range (i.e., 0 to one less than whatever number is defined as “max”). This function can be used to launch a random percentage of surveys.

For example:

=random(100) will return integers between 0 and 99 (i.e., a total of 100 integers)

For an example of how to use this function, see section Scenario Building Exercises.

replace(string, search_pattern, replace_pattern, flags)

Performs search and replace in the input string. It returns the string with replacements performed.


  • string - The input string to be searched
  • replace_pattern - The text to insert instead of matched text according to search pattern. \\0 - \\9 are allowed in replacements.
  • flags - Denoted one or more of the following additional conditions:
    • i – Ignore case in the search

For example:

Take the first name from the fullname variable and use it as the value of a Set Variable block:


round(floating_number, precision)



Removes non-digit characters from string, leaving only digits from 0 to 9, * and # symbols.

For example:

stripnondigits("123abc456") will return "123456"




This function converts an integer to a string.

For example:





Validates the entered primary account number (PAN) (i.e., the credit card number). The length of the number is checked to be within the 10 to 19 digit range; if it passes the Luhn check, it returns a 1 if the number is valid and 0 if the number is invalid.

Note: If the entered number starts with "2014" or "2149", which is a Diners enRoute Club card, the Luhn check is not performed.


Validates a four-digit credit card expiration date. The date should be in the form MMYY (four digits); the first two digits should range from 01 to 12 (month) and the last two digits shoud range from 00 to 99 (year).

The function validates the expiration date and returns the value 1 if the data is valid and 0 if the data is invalid.

Note: This function does not check the specified date against the current date, as in some cases payment processors may honor expired cards.


Validates a credit card's CCV; it returns a 1 if the data is valid and 0 if the data is invalid.

Both three-digit and four-digit CCV numbers are recognized. A four-digit value is recognized as valid for Amex (i.e., based on analysis of a previously entered PAN); a three-digit value is recognized as valid for all other cards.

Pattern Types

Pattern Description
^ Match beginning of a buffer
$ Match end of a buffer
() Grouping and substring capturing
[…] Match any character from the set
\\s Match whitespace
\\S Match non-whitespace
\\d Match decimal digit
\\D Match anything but decimal digit
\\r Match carriage return
\\n Match new line
+ Match one or more times (greedy)
+? Match one or more times (non-greedy)
* Match zero or more times (greedy)
*? Match zero or more times (non-greedy)
? Match zero or once

< Previous | Next >