These functions check whether a source contains a specific value. The result returned is either true or false (Boolean). Functions that produce a Boolean value are useful for building personalization rules and selections.
Function Overview
Function | Description |
|---|---|
fn:contains | Determines whether a target string contains a specified substring. |
fn:containsIgnoreCase | Determines whether a target string contains a specified substring, ignoring the case of the target string. It ignores whether the target string text is written in upper or lowercase. |
fn:endsWith | Tests if a target string ends with the specified substring. |
fn:startsWith | Tests if a target string starts with the specified substring. |
fn:indexOf | Returns the index within a string of a specified substring. |
ecm:regexMatches | Determines whether a specified value matches a given regular expression. |
ecm:regexMatchesIgnoreCase | Determines whether a specified value matches a given regular expression. It ignores whether the target string text is written in upper or lowercase. |
ecx:isEmptyCouponList | Determines whether coupon codes remain in the specified coupon list. |
fn:contains
The function fn:contains determines whether a target string contains a specified substring. The value returned is a Boolean data type.
Example
The job title Manager is stored in the attribute user.CustomAttribute['job title'] and is always entered as "Manager". All recipients with this job title receive a special line of text in their message. The line of text is inserted into the message using an InsertIf statement, which is constructed as follows:
<%InsertIf expression="${fn:contains(user.CustomAttribute['job title'], 'Manager')}"%>Text<%/InsertIf%>Structure
fn:contains(string, string)
Parameters
Parameter | Description |
|---|---|
string | Specifies the target string. |
string | The value (substring) used to query the target. |
fn:containsIgnoreCase
The function fn:containsIgnoreCase determines whether a target string contains a specified substring. It ignores whether the target string text is written in upper or lowercase. The value returned is a Boolean data type.
Example
The job title Manager is stored in the attribute user.CustomAttribute['job title']. The attribute may contain "Manager", "manager" or "MANAGER", etc. All recipients with 'manager' (any case) receive a special line of text in their message. The line of text is inserted into the message using an InsertIf statement, which is constructed as follows:
<%InsertIf expression="${fn:containsIgnoreCase(user.CustomAttribute['job title'], 'manager')}"%>Text<%/InsertIf%>Structure
fn:containsIgnoreCase(string, string)
Parameters
Parameter | Description |
|---|---|
string | Specifies the target string. |
string | The value (substring) used to query the target. |
fn:startsWith
The function fn:startsWith determines whether a target string starts with the specified substring. The value returned is a Boolean data type.
Example
A special message is sent to recipients within a specific postal code. The function searches the target attribute user['ZipCode'] for the value 'SW'. The line of text is inserted into the message with an InsertIf statement, which is constructed as follows:
<%InsertIf expression="${fn:startsWith(user['ZipCode'], 'SW')}"%>Text<%/InsertIf%>Structure
fn:startsWith(string, string)
Parameters
Parameter | Description |
|---|---|
string | Specifies the target string. |
string | The value (prefix) used to query the target. |
fn:endsWith
The function fn:endsWith tests if a target string ends with the specified substring. The value returned is a Boolean data type.
Example
Recipients with Gmail accounts are welcomed with a specific message. The function searches the target attribute user['Email'] for the value 'gmail.com'. The line of text is inserted into the message with an InsertIf statement, which is constructed as follows:
<%InsertIf expression="${fn:endsWith(user['Email'], 'gmail.com')}"%>Text<%/InsertIf%>Structure
fn:endsWith(string, string)
Parameters
Parameter | Description |
|---|---|
string | Specifies the target string. |
string | The value (suffix) used to query the target. |
fn:indexOf
The function fn:indexOf returns the index within a string of a specified substring. The value returned is an integer data type.
Example
Customer purchase orders are stored in a related data set. The product names include a model number. The related data set is called Orders and is linked to the user attribute user.Email. The model number is preceded by a forward slash character (/). The product name is inserted into a message without the product number.
This example uses the function fn:indexOf to determine the index number of the special character and extract only the product name using the fn:substring function (see fn:substring). The function for locating the index of the forward slash is constructed as follows:
fn:indexOf(user.relatedAttribute['Orders']['ProductName'], "/")The function returns an integer which equals the index of the special character. When used inside a fn:substring function that returns only the product name, it appears as follows:
${fn:substring(user.relatedAttribute['Orders']['ProductName'], "", fn:indexOf(user.relatedAttribute['Orders']['ProductName'], "/"))}In this example, the result returned from the fn:indexOf function is used as the parameter that defines the first character to be excluded from the substring. The parameter that defines the first character to be included is left blank. The substring returned includes anything that precedes the forward slash, no matter where it appears in the data set. Given that there can be more than one order per user in the data set, a ForEach loop is used to include all the order information in a message. For more information on constructing a ForEach loop, see Insert Related Data Records Into Messages.
The first character counted in the target string has an index value of 0, not 1.
Structure
fn:indexOf(string, string)
Parameters
Parameter | Description |
|---|---|
string | Specifies the target string. |
string | The value (substring) used to query the target. |
ecm:regexMatches
The function ecm:regexMatches determines whether a specified value matches a given regular expression. The value returned is a Boolean data type.
Example
A message is customized for recipients with email addresses from Yahoo, Gmail, or Hotmail. A line of text is inserted into the message using an InsertIf statement, which is structured as follows:
A message is customized for recipients with email addresses from Yahoo, Gmail, or Hotmail, including country-specific domains like yahoo.de. A line of text is inserted into the message using an InsertIf statement, which is structured as follows:
<%InsertIf expression="${ecm:regexMatches(user['Email'],'.+@(yahoo|gmail|hotmail)\..+')}"%>Text<%/InsertIf%>The characters included in the regular expression define the query as follows:
The period (.) indicates that a single character exists in the queried element which does not have to match the regular expression.
The plus sign (+) indicates that there are one or more of the preceding elements (a single character). This means that anything that appears before the @ sign in the email address is returned.
The parenthesis () define the subexpression, in this case, the three email domains.
The vertical bar (|) separates alternative items included in the query.
The backslash (\) escapes the expression to show that the character that follows (the period) is a regular character to include in the query.
The combination of a period and plus sign (.+) is repeated to indicate that one or more characters exist that do not have to match the regular expression
The whole regular expression must match to be true. For example, if you want to check if an email contains AOL, you must include variables that take into account any characters that could appear before or after AOL in the target string.
Structure
ecm:regexMatches(string, string)
Parameters
Parameter | Description |
|---|---|
string | Specifies the target string that is queried against the regular expression. |
string | The regular expression, in single quotes. The regular expression defines how the query is performed. |
ecm:regexMatchesIgnoreCase
The function ecm:regexMatchesIgnoreCase checks to see if a specified value matches a given regular expression. It ignores whether the target string text is written in upper or lowercase. The value returned is a Boolean data type.
Example
A message is customized for recipients residing in London, Paris or Milan. However, the value saved in the attribute is not always formatted properly, for example, london/pARIS/mIlAn. The placeholder should insert the text when the attribute value matches regardless of how it is written. A line of text is inserted into the message using an InsertIf statement, which is structured as follows:
<%InsertIf expression="${((ecm:regexMatchesIgnoreCase(user.customAttribute['City'],'(London|Paris|Milan)')))}"%>Text<%/InsertIf%>The characters included in the regular expression define the query as follows:
The parenthesis ( ) define the subexpression, in this case, the three cities to be considered for the personalization.
The vertical bar (|) separates alternative items included in the query
The whole regular expression must match to be true. For example, if you want to check if an email contains AOL, you must include variables that take into account any characters that could appear before or after AOL in the target string
Structure
ecm:regexMatchesIgnoreCase(string, string)
Parameters
Parameter | Description |
|---|---|
string | Specifies the target string that is queried against the regular expression. |
string | The regular expression, in single quotes. The regular expression defines how the query is performed. |
ecx:isEmptyCouponList
The function ecx:isEmptyCouponList determines whether coupon codes remain in the specified coupon list. The value returned is a Boolean data type.
Examples
A message displays coupon codes from a coupon list. Personalization is displayed in the message when there is a coupon available and also when there are no coupons remaining.
The placeholder that marks where the personalisation is inserted when coupons are available in the coupon list is constructed as follows:
<%InsertIf expression="${(ecx:isEmptyCouponList(coupon['MyCouponList'])=='false'))}"%>Instructions for redeeming the coupon.<%InsertIf%>As long as there are coupons in the list, this function returns the value false. Comparing this result with the equals operator == to the static value 'false' returns the Boolean true, which satisfies the condition for inserting the personalization.
The placeholder that marks where the personalisation is inserted when no coupons are available in the coupon list is formatted as follows:
<%InsertIf expression="${ecx:isEmptyCouponList(coupon['MyCouponList'])}"%>No coupons left.<%InsertIf%>When there are no remaining coupons in the target list, this function returns the Boolean true, which satisfies the condition for inserting the personalization.
Structure
ecx:isEmptyCouponList(object)
Parameters
Parameter | Description |
|---|---|
object | The name of the coupon list. |