I know that script tokens can be used in the subject line. So I have a path to achieve this in any case.
I am hoping to confirm if it is possible to use a variable from a script token in the subject line when the token lives in the body of the email. (I see it working in the preview but I don't always trust the preview when it comes to rendering scripting tokens.)
For example, I have a token at the top of my template that defines a number of variables that are used throughout the message body. These pull from a custom object so I define them all at the top of the message so I'm not hitting the object repeatedly throughout the message and it helps keeps things neat. In this example, I have a month field that gets populated with the short name for the month as a string. I am using a map to get the full name of the months and writing them to $startMonthFull and $endMonthFull.
#set($startMonth = $accountStatsData_cList.get(0).MONTH_START_NAME)
#set($endMonth = $accountStatsData_cList.get(0).MONTH_END_NAME)
#set($monthMap = {})
#set($month = $monthMap.put("Jan", "January"))
#set($month = $monthMap.put("Feb", "February"))
#set($month = $monthMap.put("Mar", "March"))
#set($month = $monthMap.put("Apr", "April"))
#set($month = $monthMap.put("May", "May"))
#set($month = $monthMap.put("Jun", "June"))
#set($month = $monthMap.put("Jul", "July"))
#set($month = $monthMap.put("Aug", "August"))
#set($month = $monthMap.put("Sep", "September"))
#set($month = $monthMap.put("Oct", "October"))
#set($month = $monthMap.put("Nov", "November"))
#set($month = $monthMap.put("Dec", "December"))
#set($startMonthFull = $monthMap.get($startMonth))
#set($endMonthFull = $monthMap.get($endMonth))
Can I used $startMonthFull and $endMonthFull in my subject line and expect it to render properly in production sends?
Solved! Go to Solution.
No, using Velocity variables ($references
) outside of Email Script {{my.tokens}} is not supported.
However, you can create 2 simple {{my.tokens}} each outputting one variable. As long as the main {{my.token}} is parsed first, all subsequent tokens can output the variables. That is, all Velocity code shares the same scope.
Also, you don’t need that map to convert between short month names and long. Both values are built into SimpleDateFormat.
## $shortMonth is "Dec"
#set( $tempDate = $convert.parseDate($shortMonth, "MMM") )
#set( $longMonth = $date.format("MMMM", $tempDate) )
## $longMonth is "December"
No, using Velocity variables ($references
) outside of Email Script {{my.tokens}} is not supported.
However, you can create 2 simple {{my.tokens}} each outputting one variable. As long as the main {{my.token}} is parsed first, all subsequent tokens can output the variables. That is, all Velocity code shares the same scope.
Also, you don’t need that map to convert between short month names and long. Both values are built into SimpleDateFormat.
## $shortMonth is "Dec"
#set( $tempDate = $convert.parseDate($shortMonth, "MMM") )
#set( $longMonth = $date.format("MMMM", $tempDate) )
## $longMonth is "December"
As always, thank you Sanford!