Using variable from script token in the subject line | Community
Skip to main content
peter_fedewa1
New Participant
June 12, 2024
Solved

Using variable from script token in the subject line

  • June 12, 2024
  • 2 replies
  • 1869 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

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.

2 replies

SanfordWhiteman
New Participant
June 12, 2024

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"

 

peter_fedewa1
New Participant
June 14, 2024

As always, thank you Sanford!

- Peter
SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
June 12, 2024

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.