Using RPL instead of built-in functions

The following section shows examples of how to use RPL instead of built-in functions.

Accessing variables and fields

The simplest template is an HTML or plain text file. When the system emails a user, RPL sends that HTML as is. However, to make the message to be more dynamic, you can include instructions for RPL in the HTML:

Using built-in functions Using RPL

Generally, the syntax for referring to fields/columns from a data source is:

Datasaourcealias.fieldnamealias
$Lookup(Field)$
${Datasourcealias.Fieldalias}
$Lookup(Variable)$
${Variable}

We also support simple replacements:

$Field$
Dear $Lookup(FIRST_NAME)$
Dear
${ContactList.FIRST_NAME}

Assuming all the fields above are coming from the profile list called ContactList.

Using conditions

Using built-in functions Using RPL
$cond(condition, onTrue, onFalse)
<#if condition>
	…text for true case
<#else>
	… text for false case
</#if>
$cond(eq(Lookup(Travel), 'Y'), document(Travel, TravelOffer), nothing())$
<#if Travel='Y'>
	<table>
		<tr>…</tr>
	</table>
</#if>

Using operators

Using built-in functions Using RPL

Generally, the syntax for referring to fields/columns from a data source is:

Datasaourcealias.fieldnamealias
$add(2,mul(5*Price))$ $and(ge(Price, 1000.00), le (Price, 2000.00))$
${2 + 5*Price}
${(Price >= 1000.00 && Price <= 2000.00)}
Parentheses are used to tell RPL not to interpret ">" or "<" as a tag markers
${Price ge 1000.00 && Price le 2000.00}
String concatenation: $concat(FIRST_NAME, concat(space(), LAST_NAME))$
${ContactList.FIRST_NAME + " "+ ContactList.LAST_NAME}
This example assumes that all fields are coming from the profile list called ContactList.

Abour RPL built-ins

RPL includes a set of routines that allow for some common programing tasks such as converting text to uppercase and converting a number to a string. These routines are called built-ins. Do not confuse these with Responsys built-in functions as they are different.

You specify built-ins as expression? built-in name.

Here are some examples of how you can use RPL built-ins instead of built-in functions.

Using built-in functions Using RPL

Generally, the syntax for referring to fields/columns from a data source is:

Datasaourcealias.fieldnamealias

The examples below assume that all fields are coming from the profile list called ContactList.

$uppercase(Region)$ 
${ContactList.Region?upper_case}
$leadingcapital(City)$ 
${ContactList.City?cap_first}
$capitalizewords(Location)$ 
${ContactList.Location?capitalize

Looking up records and looping

Using built-in functions Using RPL
$COND(EMPTY(
LOOKUPRECORDS(!Event Tables, Events_All_Next_21_Days,
PAIRS(GENRE_CATEGORY_DESCR, MLB Tickets, Region_Name,
LOOKUP(Region_Name)), Event_ID)), NOTHING(),
ESCAPECOMMAS(DOCUMENT(
Modules, MOD_TU_Event_Sports_Baseball_MLB)))$
<table>
<#data Events_All_Next_21_Days as event>
	<#filter description="MLB Tickets"
		region_name=Region_Name>
	<#fields eventid description city state date_local>
	<tr><td>…${event.city}…</td></tr>
</#data>
</table>

Including a document

Using built-in functions Using RPL
$document(folderName, doc1, doc2, …)$
$document(folderName, doc1, pairs(name1,
value1, name2, value2, ...))$
$documentnobr(folderName, doc1, doc2, …)$
<#include "cms://contentlibrary/folderName /doc1.RPL">
<#include “cms://contentlibrary/folderName /doc2.html” parse=“false”>
<#list docList as doc>
	<#assign random=rand(0,2000)>
<#-- available in included doc - ->
	<#include "cms://contentlibrary/folderName /" + doc>
</#list>

Using RPL built-ins

This section shows how to use some common RPL built-ins.

To do this Specify this
Convert a string to a date
"2013-03-27"?date("yyyy-MM-dd")
Convert a number to a string in currency format
7326847?string.currency
Protect a string for html output
pet.description?html
Convert a number to hex format
123?hex
Convert a string to hex format (Responsys built-in function equivalent)
"abc"?hex
Skip a user’s record if a string is empty
profile.firstname?skip
Sort a sequence
list5?sort
Get all the keys of a hash
fruitColors?keys

Next steps

RPL Concepts

Most commonly used directives

Learn more

Responsys Personalization Language (RPL)