Marketo nation; I am in need of help on email creation and variable/conditional token logic. I have an email requirement that must allow for the following:
One of the following two options must be met in the content of the email body:
Option A: "My family has the following pets: Dog, cat, fish, and lizard"
Option B: "My family has the following pets:
Dog
Cat
Fish
Lizard"
The problem however, is that there could be anywhere from 1-13 pets listed in this business case. For example, leadA may have 3 pets, leadB may have 9 pets. We've never been asked to build this level of "token-ization" in Marketo, nor do I know if it's possible. In option A, we'd have no idea how to dynamically insert the "," value or the "and" value before the last variable. Meanwhile, in option B, we' have no idea how to eliminate the line breaks if there are fewer than 9 pets.
Has anyone ever had to do this? Essentially, we're sending an email to our customers letting them know which products they've signed up for. We're open to any/all ideas the nation may have. Thanks in advance.
Switching the layout from comma-delimited to an indented list is very simple using a Velocity script.
The question is how these values exist in the first place. Are they already in a consistent comma- or semi-colon delimited string field?
They come to me like this: emailaddress;firstname;lastname;dog;cat;;;bird;lizard;;;
The double semi-colons represent a column header for which the lead has no value in
Simple stuff: semi-delimited with an offset. This is already in a text/textarea field?
This Velocity script will do the job nicely. You set the input.startOffset to the number of items to skip (in your example, 3) and output.short.maxSize to the maximum items to display comma-delimited (longer than that switches to line breaks).
#set( $config = {
"input" : {
"delimiter" : ";",
"startOffset" : 3
},
"output" : {
"short" : {
"maxSize" : 3,
"delimiter" : ", ",
"prependToLastItem" : "and "
},
"long" : {
"delimiter" : "<BR>\u000a",
"prependToLastItem" : ""
}
}
} )
## No need to edit below this line!
#set( $rawparts = $lead.pets.split( $config.input.delimiter ) )
#set( $parts = [] )
#foreach( $rawpart in $rawparts )
#if( $velocityCount > $config.input.startOffset && !$rawpart.isEmpty() )
#set( $tmp = $parts.add($rawpart) )
#end
#end
#if( $parts.size() <= $config.output.short.maxSize )
#set( $activeConfig = $config.output.short )
#else
#set( $activeConfig = $config.output.long )
#end
#foreach( $part in $parts )
#if( $velocityCount < $parts.size() )
${part}${activeConfig.delimiter}##
#else
${activeConfig.prependToLastItem}${part}##
#end
#end
Hi Duke,
How are you collecting the data? Do you have multiple fields flagged as true/false (i.e. a field for dog, a field for cat), or do you have one field with multiple pets (this is what it sounds like from the way your question is worded)?
The data comes to me like this in semi-colon deliminated files
emailaddress;firstname;lastname;dog;cat;;;bird;lizard;;;
Where there are 2 consecutive semi-colons its because they dont have a pet that is one of the column headers.
There is a post on using Velocity scripting if you are interested.
I am interested.