The last several email scripting projects I’ve worked on have proved to be good use cases for a Velocity Script’s powerful feature, the use of temporary objects with multiple email script tokens. This feature allows marketers to efficiently manage and manipulate data, enabling them to create more engaging and personalized email campaigns. In this blog post, I’ll explore these features in more depth, discussing their benefits and best practices for implementation.
Temporary objects in Velocity Script can be an array or structured object. These objects are particularly useful to store a subset of records from a custom object. Temporary objects can also be populated by evaluating JSON stored in a field or from a custom object record. ETL processes can be used to transform the data before storing it in the object.
In a recent use case, my customer wanted to send birthday greetings to pet owners on their birthday. The pet information is stored in a custom object. An owner may have one or more pets and the custom object holds pet information for current and past pets.
There were multiple sections on the email that was personalized. For example, the hero banner is different a cat or dog. The pet’s name(s) were used in different sections. For owners with multiple pets, the names were required to be listed, ie. Happy Birthday Spot and Rover.
The first token, PetBirthdays, is used get all the records for living pets whose birthday was today.
##PetBirthday
#set( $pets = [] )
#set( $cal = $date.getCalendar() )
#set( $ret = $cal.add(5,-1) )
#set( $today = $date.format('MMdd', $cal) )
#foreach( $pet in $pet_cList )
#set( $petBDay = $date.format('MMdd',$convert.parseDate($pet.dateOfBirth,'yyyy-MM-dd')) )
#if( $petBDay == $today && ! $pet.deceased == true )
#set( $ret = $pets.add($pet) )
#end
#end
These records were added to an array $pets using add function. #set( $ret = $pets.add($pet) ). Note: the set directive is used to call the add function. The variable, $ret is only used to record the response.
In the right navigation, the fields used in the additional scripts are selected here. This is not required in the other scripts.
The pets with birthdays have been determined and added to the array.
This token is added to be beginning of the email. A great place to put the first token is in the From of the email editor.
The rest of the script tokens can be written to use these records by referencing the $pets array.
In this example, the pet names are combined depending on the number in the array.
##Pet Birthday Names
#set( $namepet = "your pets" )
#set( $listSize = $pets.size() )
#if( $listSize == 1 )
#set( $namepet = $pets[0].name )
#elseif( $listSize == 2 )
#set( $namepet = "${pets[0].name} and ${pets[1].name}" )
#elseif( $listSize == 3 )
#set( $namepet = "${pets[0].name}, ${pets[1].name} and ${pets[2].name}" )
#end
${namepet}
The script is simplified because the number of pet records have already been determined. The records do not need to be extracted from the custom object again.
In conclusion, Marketo's Velocity scripting language offers marketers a powerful tool for creating dynamic and personalized email campaigns. By using temporary objects and multiple email script tokens, marketers can efficiently manage and manipulate data, leading to more engaging and effective email campaigns. By following best practices for implementation, marketers can maximize the impact of their Velocity scripts and drive better results from their email marketing efforts.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.