SOLVED

Date Format Velocity Script

Go to solution
Anonymous
Not applicable

Re: Date Format Velocity Script

Hi Dan,

Send yourself a sample using one of your preview leads. Script tokens won't render in preview mode (which is fairly worthless to begin with, IMO). Marketo has to actually run the script for it to insert anything and it will only do that when shooting an email out. Make sense?

Dan_Askin
Level 4

Re: Date Format Velocity Script

The above error is the message I get when I try to send the sample:

An error occurred when procesing the email Body!

Lexical error, Encountered: "\u201c" (8220), after : "" at *unset*[line 200, column 239] near

</tr>

<tr>

<td style="background-color:#ffffff;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;border-collapse:collapse;">

  <tab

Anonymous
Not applicable

Re: Date Format Velocity Script

Hi Dan. Your parenthesis seem out of whack.

You have:

$date.format('MMM dd, yyyy hh:mm tt', ${convert.parseDate(${lead.client_saintsseatrelocation}), 'yyyy-MM-dd HH:mm:ss')})

Try:

$date.format('MMM dd, yyyy hh:mm tt', ${convert.parseDate($lead.client_saintsseatrelocation, 'yyyy-MM-dd HH:mm:ss')})

Also, I'm not sure waht "tt" is. AM/PM is actually lowercase "aa" if that's what you're looking for.

Anonymous
Not applicable

Re: Date Format Velocity Script

Your error output looks like what it does when you forget to check the box next to the field in the script window. Are you sure the "lead.myvu_enrolled_date" field is checked?

Anonymous
Not applicable

Re: Date Format Velocity Script

It is checked (that is always frustrating to test something for an extended period of time only to realize the box was unchecked!). I have contacted support about this problem - this token in particular only works in samples, never as an alert.

Anonymous
Not applicable

Re: Date Format Velocity Script

Ryan,

How would you go about adding a week to a date stored in a variable?

Thanks

Anonymous
Not applicable

Re: Date Format Velocity Script

Hi Reed... I haven't quite mastered adding a date to a specific field... but I have come up with a way around it. Not sure if this will work in your situation but:

If my smart list is triggering off of a SFDC custom field "Purchase Date" being 5 days ago, I can use "Today" as the field to add to. So say I want to place a date in an email that is 20 days from the date they purchased, but I want to send the email 5 days after they purchased, I can just add 15 days to today's date and place it in the email with this scripted token:

#set($x = $date.calendar)

$x.add(5,15)

$date.format('EEEE, MMMM dd, yyyy',$x)

I'm determined to figure out how to add days to existing date fields.

Anonymous
Not applicable

Re: Date Format Velocity Script

Okay, well after trying the same thing for weeks, it finally worked:

#set($lead.ProspectDate = $date.calendar)

$lead.ProspectDate.add(5,36)

$date.format('EEEE, MMMM dd, yyyy',$lead.ProspectDate)

"36" is where you put how many days you want to add to the date. "5" represents that are you adding calendar days. Good luck!

Phillip_Wild
Level 10

Re: Date Format Velocity Script

Hey team

I'm trying something similar, but when I use the code given to Jim it's not working for me. Here's my code:

#set ($listlength = ${abandonedCart_cList.size()})

#set( $lastIndex = $math.sub($listlength,1) )

#set($str = $convert.parseDate(${abandonedCart_cList.get($lastIndex).serviceStartDate}, "yyyy-MM-dd HH:mm:ss")) 

$date.format('medium',$str) 

I only get the output $date.format('medium',$str)  instead of the formatted date. Why? Those last two lines are identical to what seemed to be working above, just with my variables substituted in.

Any ideas?

SanfordWhiteman
Level 10 - Community Moderator

Re: Date Format Velocity Script

Look for any of my posts where I show data parsing + display.

Make sure the date you're parsing really is in that string format, and debug each variable as you build it up. Plus wouldn't call the date variable $str as it's a Java Date at that point, not a String.