Recipient data

  • Updated

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()

Generating bar codes

If you use the coupon system to generate machine-readable bar codes, you can use Velocity to create bar code field functions based on your recipient list fields.

To create bar code field functions, you need the following information:

  • Recipient list field. Internal name of the recipient list field you want to use for the bar code.
    • EAN-13 bar code. Use the value ean13barcode.
    • Code 128 bar code. Use one of the following values:
      • Default character set: code128barcode (automatically switches between the character sets A, B, and C)
      • Character set A: code128abarcode
      • Character set B: code128bbarcode
      • Character set C: code128cbarcode
    • Interleaved 2 of 5 bar code. Use the value twooffivebarcode.Bar code type. Select one of the following bar code types:
  • Bar code size. You can specify the bar code size using the width and height in pixels or the line thickness in pixels (1-10). If you do not specify any size, the default size of 350 pixels (width) and 200 pixels (height) is used.

Insert the field function into your mailing using the image tag (<img src="{fieldfunction}"/>). Alternatively, you can create the field function directly with image tag, for example, <img src="${barcodeCouponImage.getImageUrlFor($user.data.coupon, "twooffivebarcode", 9)}"/>.

Width and height size option

${barcodeCouponImage.getImageUrlFor($user.data.RECIPIENTLISTFIELD, "BARCODETYPE", WIDTH, HEIGHT)}

Line thickness size option

${barcodeCouponImage.getImageUrlFor($user.data.RECIPIENTLISTFIELD, "BARCODETYPE", LINETHICKNESS)}

Generating QR codes

If you use the coupon system to generate machine-readable QR codes, you can use Velocity to create QR code field functions based on your recipient list fields.

To create QR code field functions, you need the following information:

  • Recipient list field. Internal name of the recipient list field you want to use for the QR code.
  • Bar code type. For the line thickness size option, specify the type "qrcode".
  • QR code size. You can specify the QR code size using the width and height in pixels (100-1850) or the line thickness in pixels (1-10).

Insert the field function into your mailing using the image tag (<img src="{fieldfunction}"/>). Alternatively, you can create the field function directly with image tag, for example, <img src="${barcodeCouponImage.getImageUrlForQrCode($user.data.coupon, 300)}"/>.

Width and height size option

${barcodeCouponImage.getImageUrlForQrCode($user.data.RECIPIENTLISTFIELD, WIDTHANDHEIGHT)}

Line thickness size option

${barcodeCouponImage.getImageUrlFor($user.data.RECIPIENTLISTFIELD, "qrcode", LINETHICKNESS)}