The following are the lists of available functions.
Date and Time Functions
Field Name | Description and examples |
---|---|
fn.datetostr(date, pattern) | Converts a date into a string value.Example: fn.datetostr(contact.values.BIRTHDATE, 'dd/MM/yyyy') |
fn.datetostr_tz(date, pattern, timezone) | Converts a date into a string value. This function is applied using a specific timezone.Example: fn.datetostr_tz(contact.values.BIRTHDATE, 'dd/MM/yyyy', 'Europe/Rome') |
fn.strtodate(string, pattern) | Converts a string value into a date.Example: fn.strtodate(contact.values.MYFIELD, 'dd/MM/yyyy HH:mm') |
fn.strtodate_tz(string, pattern, timezone) | Converts a string into a date value. This function is applied using a specific timezone.Example: fn.strtodate_tz(contact.values.MYFIELD, 'dd/MM/yyyy HH:mm', 'Europe/Rome') |
fn.now() | Returns the current date and time. |
fn.today() | Returns today’s date with the time set to 00:00:00. |
fn.today_tz(timezone) | Returns today’s date with the time set to 00:00:00 in the specified timezone. |
fn.midnight(date) | Returns the given date with the time set to 00:00:00. |
fn.midnight_tz(date, timezone) | Returns the given date with the time set to 00:00:00 in the specified timezone. |
fn.dateadd(date, offset, unit) | Adds a time value to a date in a specific unit (year, month, day, hour, minute, second, dayofweek). Example: fn.dateadd(contact.values.EXPIREDATE, -2, 'day') |
fn.dateadd_tz(date, offset, unit, timezone) | Adds a time value to a date in a specific unit (year, month, day, hour, minute, second, dayofweek). This function is applied using a specific timezone. Example: fn.dateadd_tz(contact.values.EXPIREDATE, -2, 'day', 'Europe/Rome') |
fn.datediff(date1, date2, unit) | Returns an int representing the difference between two dates in a specified unit (year, month, day, hour, minute, second, dayofweek). Example: fn.datediff(fn.now(), contact.values.EXPIREDATE, 'day') |
fn.datepart(date1, unit) | Returns a string representing the part of a date that corresponds to the given unit (year, month, day, hour, minute, second, dayofweek).Example: fn.datepart(contact.values.EXPIREDATE, 'month') |
fn.datepart_tz(date1, unit, timezone) | Returns a string representing the part of a date that corresponds to the given unit (year, month, day, hour, minute, second, dayofweek).This function is applied using a specific timezone. Example: fn.datepart_tz(contact.values.EXPIREDATE, 'month', 'Europe/Rome') |
fn.age(date) | Returns an int representing the age based on a date, in years.Example: fn.age(contact.values.BIRTHDATE) |
fn.age_tz(date, timezone) | Returns an int representing the age based on a date, in years. This function is applied using a specific timezone.Example: fn.age(contact.values.BIRTHDATE) |
fn.anniversary(birthday) | Returns the anniversary date (if already passed, the date of the next anniversary). |
fn.anniversary_tz(birthday, timezone) | Returns the anniversary date (if already passed, the date of the next anniversary). This function is applied using the given timezone. |
String Functions
Field Name | Description and examples |
---|---|
fn.ucase(string) | Converts a string to UPPERCASE. If applied to a list, the function is applied to all its elements. |
fn.lcase(string) | Converts a string to lowercase. If applied to a list, the function is applied to all its elements. |
fn.capitalcase(string) | Capitalizes the first letter of each word and makes the others lowercase. If applied to a list, the function is applied to all its elements. |
fn.trim(string) | Removes all unnecessary spaces from a string. |
fn.left(string, maxchars) | Returns the left part of a string or list equal to the specified number of characters/elements. |
fn.right(string, maxchars) | Returns the right part of a string or list equal to the specified number of characters/elements. |
fn.mid(string, from, to) | Extracts a portion of a string or list (from=0 is the first element, to is always required). |
fn.len(var) | Returns the length of a string or list. |
fn.concat(var1, var2) | Concatenates the string representation of two variables. null values are treated as empty strings. For date/timestamp values, it is better to format them using fn.strtodate_tz . |
fn.if(condition, value1, value2) | If the condition evaluates to true, returns value1, otherwise returns value2. Accepted values for the condition are: true, false, ‘true’, ‘false’, ‘0’, ‘1’, 0, 1. |
fn.ifempty(string, defaultvalue) | If the string is empty or "", returns the specified value, otherwise returns the original value. |
fn.coalesce(var, defaultvalue) | If var is empty, returns the specified value, otherwise returns the original value. Example: fn.coalesce(contact.values.ORDERS, 0) |
fn.base64_encode(string) | Encodes a utf-8 string using base64 encoding. |
fn.url_decode(string) | Decodes a string from the URL querystring parameter representation, using utf-8 encoding (java URLDecoder.decode). |
fn.url_appendparameter (url,name,value) |
Treats a url as a URL, and adds to the querystring a parameter called name with value after the “?” symbol and before the “#” symbol.The value MUST already be encoded, using the url_encode function. |
fn.replace(string, occurrence, replacement) | Sostituisce tutte le occorrenze nella stringa indicata. |
fn.strtonumber(numer_as_string, decimal_separator) | Converts the string to a number. If decimal_separator is other than null, it is considered for conversion. |
fn.md5(var) | Returns a string representing the value calculated by the MD5 algorithm and printed in base 16. |
fn.sha1(var) | Returns a string representing the value calculated by the SHA-1 algorithm and printed in base 16. |
fn.sha256(var) | Returns a string representing the value calculated by the SHA-256 algorithm and printed in base 16. |
fn.preg_replace(regex_pattern, replacement, string) | Applies a substitution via regexp on the string string with replacement. |
List Functions
Field Name | Description and examples |
---|---|
fn.strtolist(string, separator) | Converts a string into a list using the specified separator. Example: fn.strtolist('Italy,France,UK', ',') |
fn.listtostr(list, separator) | Converts a list into a string using the specified separator. Example: fn.listtostr(contact.values.COUNTRY, ',') |
fn.randomelement(list) | Returns one element from a collection or a comma-separated string list. Example: fn.randomelement('Red,Yellow,Green') |
fn.sort(list,direction) | Sorts a list using a natural sorting function (alphabetical for strings). Use direction='asc' for ascending and direction="desc" for descending.Any other value is treated as asc . |
fn.sortby(list,field,direction) | Sorts a list of records using the field value of each record.Use direction='asc' for ascending and direction="desc" for descending.Any other value is treated as asc . |
fn.filter(list,condition) | Filters a list of records based on the "condition" evaluated on each record. For primitive values like strings or numbers, use the special keyword this to refer to the value.Example with records: fn.filter(myqueryresultset,'name eq "xx"') Example with primitive values: fn.filter(fn.strtolist('Italy,France,UK', ','),'this contains "tal"') |
fn.extract(list, fieldname) | Extracts the fieldname from each list element and returns a list of those values in the same order.Example: fn.extract(listofperson, 'name') |
fn.compose(list, fieldname) | Builds a list of records (field-value pairs), each element will have a field named fieldname containing the corresponding value from the original list (same order). |
fn.first(list) | Returns the first element of the given list/collection. |
fn.last(list) | Returns the last element of the given list/collection. |
fn.elementAt(list, index) | Returns the element at position index in the list (index starts at 0). |
Math and Conversion Functions
Field Name | Description and examples |
---|---|
fn.round(var) | Returns a rounded numeric value. |
fn.max(a,b) | Returns the greater of two numeric values or two dates. |
fn.min(a,b) | Returns the smaller of two numeric values or two dates. |
fn.abs(var) | Returns the absolute value. |
fn.random(min,max) | Returns an integer between the specified minimum and maximum values (inclusive). |
fn.json_encode(obj) | Converts the given object into a JSON string. |
fn.json_decode(string) | Converts the given JSON string into the corresponding object. |
svgtopng(svgPath, pngPath, hexColor, size) |
Converts a file from SVG to PNG format, specifying color and size. |
Note: date handling functions use the time zone of the contacts for whom the code is being executed.
Examples
Boolean expression:
contact.values.language EQ 'ITA'
(contact.values.field1 EQ 4 OR contact.values.field1 EQ 5+1) AND contact.values.field2 NEQ NULL
contact.subscribed and contact.values.DOMAIN EQ 'gmail.com'
String expression:
'Value1'
contact.values.NAME & '-' & contact.values.SURNAME
Numeric expression:
(contact.values.A + contact.values.B)/2