SOLVED

My.Token Errors

Go to solution
Anonymous
Not applicable

My.Token Errors

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!

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: My.Token Errors

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.)

pastedImage_2.png

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.

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: My.Token Errors

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
Level 10 - Community Moderator

Re: My.Token Errors

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.)

pastedImage_2.png

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.

Anonymous
Not applicable

Re: My.Token Errors

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

Anonymous
Not applicable

Re: My.Token Errors

I just ran a sample email, but unfortunately I got "The promo has already ended", the else portion of the if statement.

The date in the code itself is later than the date I ran the test, so I think it's having a problem picking up the calEndOfPromo variable.

Let me know if you need any more info, thank you again for all of your help!    

SanfordWhiteman
Level 10 - Community Moderator

Re: My.Token Errors

Provide the whole token you're currently using, plus add these 2 lines at the end to dump the current dates

calNow: $date.format("yyyy-MM-dd'T'HH:mm:ss Z", $calNow)

calEndOfPromo: $date.format("yyyy-MM-dd'T'HH:mm:ss Z", $calEndOfPromo)