General Functions in Rule Expressions

In additional to traditional math expressions like addition, multiplication, division, and averaging, rule expressions provide a variety of general functions that are helpful for boolean logic, comparisons, and more. For more details on how to use expressions, check out the Introduction to Expressions article.
Math Features
  • abs(input)
    Returns the absolute value of an input number.
    abs(-20) # returns: 20
  • ceil(input)
    Rounds up and returns the smaller integer greater than or equal to the given number.
    ceil(9.1) # returns: 10
  • floor(input)
    Rounds down and returns the largest integer less than or equal to the given number.
    floor(9.9) # returns: 9
  • round(input[, precision])
    Rounds a given number to the nearest integer, or to the nearest number of decimals when given a precision.
    round(9.9) # returns: 10
    round(9.98) # returns 10
    round(9.88, 1) # returns 9.9
Boolean Logic
  • and(a, b)
    Returns true if a and b are both true
    and(1 > 0, true) # returns: true
    1 > 0 and true # returns true
    (true) and (false) # returns false
  • or(a, b)
    Returns true if either a or b are true
    or(0 >1, true) # returns: true
    0 > 1 or true # returns true
    (true) or (false) # returns true
  • not(input)
    Flips a boolean value of a given input
    not(true) # returns: false
    not(false) # returns true
    not(1 > 0) # returns false
  • count(array)
    Returns the count of the number of items in an array (especially useful when combined with filter)
    count([1,2,3]) # returns: 3
    count(filter([1,2,1,12,9,11], x > 10)) # returns: 2
  • filter(array, expression)
    Filters a given array based on the boolean expression being applied to each element of the given input array.
    filter([1,2,1,12,9,11], x > 10) # returns: [12, 11]
  • map(array, expression)
    Create a new array with the results of the expression applied to each element of the array
    map([1,2,3], x * 2) # returns: [2,4,6]	
  • pickRandom(array)
    Selects a random item from the array
    pickRandom([1,2,3])               # returns: 2
    pickRandom(['foo', 'bar', 'baz']) # returns: 'foo'
  • join(array, joiner)
    Concatenates elements of the array together using the given joiner.
    join(['foo', 'bar', 'baz'], ', ') # returns: 'foo, bar, baz'
    join(['foo', 'bar', 'baz'], '-')  # returns: 'foo-bar-baz'

General String Manipulation

  • parseJson(input)
    Parse and input string as a JSON object
    parseJson("2")                  # returns: 2
    parseJson("\"test\"")           # returns "test"
    parseJson("[1,2,3]")            # returns [1,2,3]
    parseJson("[\"foo\", \"bar\"]") # returns: ["foo", "bar"]
    parseJson("{\"value\": 2}")     # returns: {"value": 2}
  • stringify(input)
    Convert a JSON object (or number/string) into a JSON string
    stringify(2)                # returns: "2"
    stringify("test")           # returns '"test"'
    stringify([1,2,3])          # returns "[1,2,3]"
    stringify(["foo", "bar"])   # returns: '["foo", "bar"]'
    stringify({"value": 2})     # returns: '{"value": 2}'
  • concat(a, b, [c, d, ...z])
    Joins two or more strings together
    concat("foo", "bar")          # returns "foobar"
    concat("Hello", " ", "World") # returns "Hello World"
  • urlEncode(input)
    Converts a given input string to its URL encoded equivalent
    urlEncode("Mañana") # returns: "Ma%C3%B1ana"
Content Checks
  • isEmpty(input)
    Checks if a given input is ‘empty’. Returns true for an input string that is null or blank "", an array with no items, or a number that is 0. Otherwise returns false
  • contains(input, searchTerm)
    Returns true if an input contains a given searchTerm
  • indexOf(input, searchTerm)
    Returns the zero-based ‘index’ (position) of the first occurrence of a given searchTerm within an input string.
    indexOf("Hello World", "l") #returns: 2
  • lastIndexOf(input, searchTerm)
    Returns the zero-based index (position) of the last occurrence of a given searchTerm within an input string.
    lastIndexOf("Hello World", "l") #returns: 9
  • startsWith(input, searchTerm)
    Returns true if the input string begins with the given searchTerm
  • endsWith(input, searchTerm)
    Returns true if the input string ends with the given searchTerm


  • replace(input, searchTerm, replacement)
    Replaces the searchTerm with the replacement value if found in the input
    replace("Hello World", "World", "Universe")  #result: "Hello Universe" 
    replace("Hello World", "Hello ", "")         #result: "World" 
    replace("Hello, World", ",", ":")            #result: "Hello: World"
  • split(string, separator)
    Splits a given string using the separator into an array of substrings.
    split("Hello - World", " - ") #returns: ["Hello", "World"]
  • mid(input, start, length)
    Given a zero-based start position, returns the remaining length of characters. If length is omitted, returns all remaining characters.
    mid("Hello World", 6)    #returns: "World" 
    mid("Hello World", 1, 4) #returns: "ello" 
    mid("Hello World", -5)   #returns: "World"

    Note that you can use a negative start index which counts from the end of the string instead of the beginning

  • substring(input, start, end)
    Returns a substring from a given input string starting at the zero-based start position and ending at the zero-based end position. If end is omitted, returns all remaining characters.
    Note that this is different from mid() as it requires an  end index rather than  length
    substring("Hello World", 0, 5) #returns: "Hello" 
    substring("Hello World", 6)    #returns "World"
  • left(input, length)
    Returns the first length characters from an input string
  • right(input, length)
    Returns the last length characters from an input string

Remove Whitespace

  • trim(input)
    Removes all whitespace from before and after a given input string
  • trimLeft(input)
    Removes all whitespace from before a given input string
  • ltrim(input)
    Alias for trimLeft()
  • trimRight(input)
    Removes all whitespace from after a given input string
  • rtrim(input)
    Alias for trimRight()

Change Case

  • upper(input)
    Returns an input string formatted as all 'UPPER CASE'
  • lower(input)
    Returns an input string formatted as all 'lower case'
  • title(input)
    Returns an input string formatted as 'Title Case'
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.