SOLVED

Re: Using variable from script token in the subject line

Go to solution
peter_fedewa1
Level 2

Using variable from script token in the subject line

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?

Screenshot 2024-06-12 at 9.58.38 AM.png

Screenshot 2024-06-12 at 9.58.59 AM.png

- Peter
2 ACCEPTED SOLUTIONS

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Using variable from script token in the subject line

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.

View solution in original post

SanfordWhiteman
Level 10 - Community Moderator

Re: Using variable from script token in the subject line

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"

 

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Using variable from script token in the subject line

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.

SanfordWhiteman
Level 10 - Community Moderator

Re: Using variable from script token in the subject line

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
Level 2

Re: Using variable from script token in the subject line

As always, thank you Sanford!

- Peter