My.Token Errors | Community
Skip to main content
January 12, 2018
Solved

My.Token Errors

  • January 12, 2018
  • 2 replies
  • 2768 views

I'm trying to write a velocity email script that takes the user's date and subtracts it by a fixed date (promo code expiration date).

Here's my code so far:

#set ($today = $convert.parseDate($date.getDate(), "yyyy-MM-dd")

#set ($promoEnd = $convert.parseDate('2018-02-01', "yyyy-MM-dd"))

#set ($result = $date.difference ($promoEnd, $today).days)

#end

When I test it out in an email, I get this error:

"An error occurred when procesing the email Body! Encountered "#set" near" (followed by my code)

Given that Marketo converts all data types to a string, I think I need to format the dates into a number in order to effectively call the date.difference method - but other than that I'm not sure what's going wrong.

Any help would be appreciated, thanks!

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

James, please use the syntax highlighter in Advanced Editor when posting code. Otherwise, it can be next to impossible to read. (Highlight as Java as it's the closest to Velocity.)

The direct cause of your error is a simple syntax error: you're missing a closing ) on the first line.

But even if you fix that, it doesn't look like you're going about this the right way...

  • first, you must use timezone-aware code because even if you don't see that your Date objects are in a timezone, they always are
  • second, the ComparisonDateTool.Comparison object (the result of a $date.difference() call) uses accessor methods like getDays(), not simple properties like days

I updated this seminal blog post with example code for your case: http://blog.teknkl.com/velocity-days-and-weeks/#howlongwillthepromolast

Remember to include the common code block at the top of the post, where you set the time zone as is essential for all datetime work.

2 replies

SanfordWhiteman
Level 10
January 13, 2018

I'll look at this later. FYI there is a Jive bug that is causing posts to not show up for all people, thus I missed this until today.

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
January 14, 2018

James, please use the syntax highlighter in Advanced Editor when posting code. Otherwise, it can be next to impossible to read. (Highlight as Java as it's the closest to Velocity.)

The direct cause of your error is a simple syntax error: you're missing a closing ) on the first line.

But even if you fix that, it doesn't look like you're going about this the right way...

  • first, you must use timezone-aware code because even if you don't see that your Date objects are in a timezone, they always are
  • second, the ComparisonDateTool.Comparison object (the result of a $date.difference() call) uses accessor methods like getDays(), not simple properties like days

I updated this seminal blog post with example code for your case: http://blog.teknkl.com/velocity-days-and-weeks/#howlongwillthepromolast

Remember to include the common code block at the top of the post, where you set the time zone as is essential for all datetime work.

January 16, 2018

Thank you very much! Really impressed with all of this.