Functions

A function is a pre-defined process that MEP can run to perform a complex task, such as:

  • Rounding or comparing numbers
  • Formatting text or timestamps
  • Generating a PIN

You can use functions wherever you can use EL in MEP.

Unlike variables, functions have no scope. To reference some values multiple times, such as a PIN generated by a function, you must create a custom variable to hold the value.

An example function is:

${af:generatePin(6,true)}

Function syntax

A function is called in EL using the following format:

af:FunctionName(input)

The function’s name identifies the process. Unlike variable names, function names are case sensitive. The parentheses (input) contain input that a function interprets to create the output. The prefix af: identifies to MEP that it is a function.

Function input types

Inputs can be one of the following types of values:

  • Boolean
  • Integers
  • Strings
  • Floating point numbers
  • Alphanumeric strings
  • null
  • Regular expressions (regexp) — in MEP we use Java syntax
  • Variables — the variable will resolve to its value before the function is evaluated.

If you are using a function in the Subscriptions or Broadcasts tabs, you must make sure that any variable referenced by the function is also available in those areas of MEP.

If you want to include text or digit strings directly as input, you must surround the string with quote marks (you can use the back slash to escape quote characters in the string).

Examples

Function that includes a variable

If you wanted to find a UK phone number in the message body of an SMS message, you could use the following function:

getPhoneNumber(request.defaultMessage)

Function that includes an alphanumeric string

The following function compares an end user’s add date to the date 2010-01-01:

compareDate(user.addDate,"2010-01-01")

Example function with multiple inputs

The following expression uses a function to generate a PIN:

${af:generatePin(integer,Boolean)}

This function requires two inputs: the integer is the character length you want for the PIN, and Boolean determines the type of PIN—an alphanumeric string if set to true or an integer if set to false. For example, the expression:

${af:generatePin(6,true)}

would create an alphanumeric PIN that is 6 characters in length, such as "Z5E33F".