This topic describes how to process external data using field functions.
Use your specific data and recipient list fields, and test the field functions before using them in a mailing.
Displaying a JSON string as text in a mailing
If you retrieve data via API and store it as a JSON string, you can display the content as text with the following velocity code:
#set ($jsonContent = $json.readFromString(${jsonString}))
If recipient list fields contain data as JSON, you can display the content as text using the following velocity code:
#set ($jsonContent = $json.readFromString($!{user.data.RECIPIENTLISTFIELD}))
Example
You have a recipient list with a custom field in text format that contains the following JSON string:
{"clearname": "John Smith", "unsubscribelink": "http://www.example.com/unsubscribe/user-id-1234"}
In the mailing, you can use the JSON string using velocity code as follows:
#set ($jsonContent = $json.readFromString($!{user.data.custom}))Hello ${jsonContent.clearname}! To unsubscribe from the newsletter, click <a href="${jsonContent.unsubscribelink}">here</a>.
Displaying post-click data
Velocity lets you access the following post-click data and display it in a mailing:
- service ("name_of_service")
- stringValue("x")
- is()
- isNot()
- floatValue("X")
- isGreaterThan("y")
- isLessThan("y")
- isGreaterThanOrEqualTo("y")
- isLessThanOrEqualTo("y")
Using velocity field functions, you can display only the most recent post-click data. You cannot display older data.
Example
The following Velocity code lets you display the value of gvalue10 in the serviceName service:
#set($strGvalue = $!postClick.find().where().service().is("serviceName").getStringResult(10))$strGvalue
Please sign in to leave a comment.