Recipient data
This topic describes how you can use field functions to process recipient data and modify texts and time specifications.
Use your specific data and recipient list fields, and test the field functions before using them in a mailing.
Formatting dates
For example, if you have a recipient list field for the date of the last purchase, you can use a field function to display the date in the mailing text: We miss you! You last ordered something on 14.01.2020 and we would be happy to see you again! Enclosed you will find a $10 shopping voucher!
Since the date is stored in a standard format and would be displayed in the mailing text as 2020-01-14 10:12:00.0, for example, you can format the date using the following Velocity code:
$DateTimeHelper.formatDate("dd.MM.yyyy", $user.data.date)
Displaying dates from recipient list fields
To display dates from recipient list fields as formatted text, you can use the following Velocity code:
#if(!$StringHelper.isEmpty($!user.data.date))$DateTimeHelper.formatDate("dd.MM.yyyy", $user.data.date)#end
Displaying the current date
To display the current date as formatted text, you can use the following Velocity code:
$DateTimeHelper.formatDate("dd.MM.yyyy", $DateTimeHelper.getCurrentDate().getTime())
Displaying the current calendar week
To display the current calendar week as formatted text, you can use the following Velocity code:
$DateTimeHelper.formatDate("ww", $DateTimeHelper.getCurrentDate().getTime(), $Common.locale("en", "EN", ""))
Displaying periods in years
To output the period in years between the current date and the date in a recipient list field as formatted text, you can use the following Velocity code:
#set($date = $user.data.DATE_RECIPIENT_LIST_FIELD_NAME)
#if ($StringHelper.isEmpty($date))
#set($date = $DateTimeHelper.getCurrentDate().getTime())
#end
#set($durationList = $StringHelper.splitToList($DateTimeHelper.getDuration($date), 'd', false, true))
#if ($durationList.size() > 1)
#set ($days = $StringHelper.string2int($durationList.get(0), 0))
#else
#set ($days = 0)
#end
#set($years = $days / 365)
#if ($years >= 1)
You are our customer for #if ($years == 1)year#else$years years#end!
#end
The Velocity code displays, for example, the following text: You are our customer for 26 years!
Numbers and comparisons
You can use Velocity to compare numbers from recipient list fields.
Greater than
#if($user.data.RECIPIENTLISTFIELD > 10)
OUTPUT
#end
Greater or equal
#if($user.data.RECIPIENTLISTFIELD >= 10)
OUTPUT
#end
Less than
#if($user.data.RECIPIENTLISTFIELD < 10)
OUTPUT
#end
Less or equal
#if($user.data.RECIPIENTLISTFIELD <= 10)
OUTPUT
#end
Equal
#if($user.data.RECIPIENTLISTFIELD == 10)
OUTPUT
#end
Unequal
#if($user.data.RECIPIENTLISTFIELD != 10)
OUTPUT
#end
Generating random numbers
To generate a random number, for example to load a random image from the file server, you can use the following Velocity code:
#set ($random = $MathHelper.random(10))$random
The Velocity code displays a number between 0 and 10. It can also be a 0.
Replacing texts
To replace text from recipient list fields (for example HTML code with special characters for the text version), you can add the following ODR code as text content:
<odr:set value="%{user.data.RECIPIENTLISTFIELD}" var="content"/>
<odr:set value="WHAT" var="what"/>
<odr:set value="WITH" var="with"/>
<odr:set value="%{replace(content,what,with)}" var="newtext"/>
<odr:out value="%{newtext}"/>
Adding blank lines to the text version
To convert HTML breaks (<br>
) to blank lines for the text version, you can add the following ODR code as text content:
<odr:set value="%{user.data.RECIPIENTLISTFIELD}" var="content"/>
<odr:set value="WHAT" var="what"/>
<odr:set value="%{character('10')}" var="with"/>
<odr:set value="%{replace(content,what,with)}" var="newtext"/>
<odr:out value="%{newtext}"/>
Upper or lower case letters
You can use the following Velocity code to display text from recipient list fields as uppercase letters:
$user.data.RECIPIENTLISTFIELD.toUpperCase()
You can use the following Velocity code to display text from recipient list fields as lowercase letters:
$user.data.RECIPIENTLISTFIELD.toLowerCase()