Add today's date to Velocity Script Email token | Community
Skip to main content
New Participant
November 9, 2020
Solved

Add today's date to Velocity Script Email token

  • November 9, 2020
  • 1 reply
  • 2963 views

Hi there,

 

I'm currently using below token to get links in my email with modified date "2020-11-09". As I need to send out this edm every friday,. how can I change date from "2020-11-09" to today's date so I don't have to update the date in token every Friday

 

I tried tips from Sanfordwhiteman's blog but my coding skills are not great so couldn't do it https://blog.teknkl.com/velocity-days-and-weeks/

@sanfordwhiteman  thanks in advance!

 

#set( $calNow = $date.getCalendar() ) <ul style="text-align: left;"> #foreach($emailAddress in $Report_20200214_cList) #if ($emailAddress.modifiedDate == "2020-11-09") <li style="text-align: left;color: #216E9B;"><a href="${emailAddress.rANDURL}" target="_blank" style="text-decoration: none; font-size: 12px; color: #007CC2;" class="mktNoTok">${emailAddress.dealership}</a></li> #else #end #end </ul>

 

 

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

Remember to always include all the common variables from that post. Otherwise, you won't be prepared to do date math.

 

This is one case where you don't have to cast the date-like String field (the one on your Custom Object) to a real Date object, you can just compare the stringified current date with the (already-stringified) stored date.

#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( $ISO8601DateOnly = "yyyy-MM-dd" ) #set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" ) #set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" ) #set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" ) #set( $nowISO = $date.format($ISO8601DateOnly,$calNow,$defaultLocale,$defaultTimeZone) ) <ul style="text-align: left;"> #foreach($emailAddress in $Report_20200214_cList) #if( $emailAddress.modifiedDate.equals($nowISO) ) <li style="text-align: left;color: #216E9B;"><a href="${emailAddress.rANDURL}" target="_blank" style="text-decoration: none; font-size: 12px; color: #007CC2;" class="mktNoTok">${emailAddress.dealership}</a></li> #else #end #end </ul>

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
November 9, 2020

Remember to always include all the common variables from that post. Otherwise, you won't be prepared to do date math.

 

This is one case where you don't have to cast the date-like String field (the one on your Custom Object) to a real Date object, you can just compare the stringified current date with the (already-stringified) stored date.

#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( $ISO8601DateOnly = "yyyy-MM-dd" ) #set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" ) #set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" ) #set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" ) #set( $nowISO = $date.format($ISO8601DateOnly,$calNow,$defaultLocale,$defaultTimeZone) ) <ul style="text-align: left;"> #foreach($emailAddress in $Report_20200214_cList) #if( $emailAddress.modifiedDate.equals($nowISO) ) <li style="text-align: left;color: #216E9B;"><a href="${emailAddress.rANDURL}" target="_blank" style="text-decoration: none; font-size: 12px; color: #007CC2;" class="mktNoTok">${emailAddress.dealership}</a></li> #else #end #end </ul>
New Participant
November 9, 2020

Thanks a lot @sanfordwhiteman  you are a savior. This works perfect!!