Email Script: Velocity and Alternating URLs in One Email Confirmation

Allison_Isett
Level 1

Email Script: Velocity and Alternating URLs in One Email Confirmation

Hello, 
I'm hoping to get some developer insight related to switching a confirmation email's URL content based on day/time
with Velocity. Note, that I am not a developer-
I am trying to put together a script that will use one parent engagement program confirmation email that can include a personalize webinar URL based on the date of the event. The 5 webinars are nested inside of an engagement program, where I was hoping to set the script at the parent program level and the confirmation email would also trigger from the parent engagement program. 
I am getting hung up on where I would need to set the webinar dates, and URLS display the URLs? Can I set the webinar dates and URLs directly in the script token, or do I have to use separate my.tokens to set them and reference them in the script?

If the calendar date is less than Webinar 1 date
Display my webinar url 1
If the calendar date is after Webinar 1 and before Webinar 3 date
Display my webinar url 2
If the calendar date is After Webinar 2 date and before the Webinar 4 date
Display my webinar url 3
If the calendar date is After Webinar 3 date and before Webinar 5 date
Display my webinar url 4
If the calendar date is after webinar 4
Display my webinar url 5
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") ) 
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )


#if ($calNow.get($calConst.$date.getCalendar) <= {{my.webinar 1 DT}} )
#set ($mywebinardate= "{{my.webinar 1 DT}}")
#set ($mywebinarurl= "https://event.on24.com/wcc/r/2021571/16048F8C9FD8F66DE96DBE1ECEE3DFEB")
#elseif ($calNow.get($calConst.$date.getCalendar) <= {{my.webinar 2 DT}} )
#set ($mywebinardate= "{{my.webinar 2 DT}}")
#set ($mywebinarurl= "https://event.on24.com/wcc/r/2021573/51B046F601D036C3D8F47F3A80F4E779")

##print the myvalue
$mywebinardate
$mywebinarurl
#end>
5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script: Velocity and Alternating URLs in One Email Confirmation

I am getting hung up on where I would need to set the webinar dates, and URLS display the URLs? Can I set the webinar dates and URLs directly in the script token, or do I have to use separate my.tokens to set them and reference them in the script?

You can use another token, but another Velocity token, not a generic token.

If {{my.token1}} has

#set( $webinarDate = "2019-06-0712:00:00" )
#set( $webinarTZ = "America/New_York" )

and {{my.token2}} does the date processing, then you just to include {{my.token1}} before (that is, anywhere above) {{my.token2}} in the email.

{{my.token1}}{{my.token2}}

Splitting across different "data", "config", and "code" tokens is definitely a best practice for maintainability.

Allison_Isett
Level 1

Re: Email Script: Velocity and Alternating URLs in One Email Confirmation

Thanks Sanford. 

So would I set the various webinar dates in 1 velocity token that is referenced in the date processing? Also, what about the various URLs? Would they also be in their own V-Token? 

This is what I have so far in my "Date processing token" and I'm getting stuck: 

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )


#if( $calNow.get($calConst.$date.getCalendar) > {{my.webinar 1 DT}})
#set {{$mywebinardate= "{{my.webinar 1 DT}}")
#set {{$mywebinarurl= "https://event.on24.com/wcc/r/2021571/16048F8C9FD8F66DE96DBE1ECEE3DFEB")

My confirmation email needs to have these two varying values, that are dependent on the date populated: 

Event Date and Time: {{my.webinardate}}

Link: {{my.webinarurl}}

But where would my data processing token go in this scenario? What am I getting wrong?

SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script: Velocity and Alternating URLs in One Email Confirmation

Can you highlight the code using the Advanced Editor's syntax highlighter so it's readable? (Use Java as it's closest to Velocity.) Then we'll continue.

I can already see you changed from the code I suggested. Don't do that! I wasn't just sketching out a concept, that was actual valid Velocity. When you change things with adding double curly braces and such, that's breaking the syntax.

Allison_Isett
Level 1

Re: Email Script: Velocity and Alternating URLs in One Email Confirmation

I'm attempting to get the markdown to work -- hopefully, this works after I post. 

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )``
#if ($calNow.get($calConst.$date.getCalendar) <= {{my.webinar 1 DT}} )
#set ($mywebinardate= "{{my.webinar 1 DT}}")
#set ($mywebinarurl= "https://event.on24.com/wcc/r/2021571/16048F8C9FD8F66DE96DBE1ECEE3DFEB")
#elseif ($calNow.get($calConst.$date.getCalendar) <= {{my.webinar 2 DT}} )
#set ($mywebinardate= "{{my.webinar 2 DT}}")
#set ($mywebinarurl= "https://event.on24.com/wcc/r/2021573/51B046F601D036C3D8F47F3A80F4E779")

##print the myvalue
$mywebinardate
$mywebinarurl
#end>
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script: Velocity and Alternating URLs in One Email Confirmation

Feels like you need to read my blog post a lot more thoroughly. There are examples there that you aren't using, and you seem to be conceptualizing other methods that won't even compile (syntax errors).

  • don't want to overload the <= operator to compare dates, use compareTo
  • refer to Velocity variables from other tokens using the usual $name syntax, not {{my.token}} syntax w/curly braces (curly braces are not meaningful in Velocity)
  • your #if/#elseif/#end and output doesn't look to be nested correctly
  • other syntax weirdness

Maybe you need to get a Velocity developer involved?