Hello,
It's been a while since I formatted dates with Velocity, I'm struggling with the DateTool methods and was wondering if someone had an example.
Here's my snippet:
##sets timestamp variable
#set ( $NextAppointment = ${OpportunityList.get(0).NextPhoneCallAppointment__c})
##This displays the timestamp unformatted
$NextAppointment
##This should display the timestamp formatted
$date.format('medium',$NextAppointment)
My sample emails renders like this, clearly the method is working:
2015-06-18 17:30:00 $date.format('medium',$NextAppointment)
I was using this example to get to this state:
DateTool (VelocityTools 2.0-beta4 Documentation)
Any help would be greatly appreciated as to what I might be doing incorrectly on calling the method.
Solved! Go to Solution.
So with "medium" you're wanting something like Jun 18, 2015 5:30 PM?
If that's the case, something like this might work. I tested it with a similar field but don't know what format you're date was originally in:
$date.format('MMM dd, yyyy hh:mm aa', ${convert.parseDate(${OpportunityList.get(0).NextPhoneCallAppointment__c}), 'yyyy-MM-dd HH:mm:ss')})
So with "medium" you're wanting something like Jun 18, 2015 5:30 PM?
If that's the case, something like this might work. I tested it with a similar field but don't know what format you're date was originally in:
$date.format('MMM dd, yyyy hh:mm aa', ${convert.parseDate(${OpportunityList.get(0).NextPhoneCallAppointment__c}), 'yyyy-MM-dd HH:mm:ss')})
**Update**
Works like a charm I did one slight modification:
#set($str = $convert.parseDate(${OpportunityList.get(0).NextPhoneCallAppointment__c}, "yyyy-MM-dd HH:mm:ss"))
$date.format('medium',$str)
Ryan,
Thank you so much for the response, I really appreciate it.
Let me give it a try.
Jim
Super helfpul Ryan, just ran across this and it solved my email script token date formatting issue.
Here's my entire script where the formatting is being used:
#if (${OpportunityList.get(0).New_Appoinment_c__c} != "")
$date.format('MMM dd, yyyy hh:mm aa', ${convert.parseDate(${OpportunityList.get(0).New_Appoinment_c__c}, 'yyyy-MM-dd HH:mm:ss')})
#else
Please contact us to confirm your appointment.
#end
And this will display/print the date and time text from the New Appointment field on the opportunity in an email subject or body like this:
Aug 07, 2015 09:25 AM
We are getting a strange error on this....the script works fine in samples, but when actually sending this as an alert it breaks down (even though we are positive these leads have values in their lead level field). The campaign can only be run when those exact values get populated, so I'm not sure why this is happening...
#if (${lead.myvu_enrolled_date} != "")
$date.format('MMM dd, yyyy hh:mm aa', ${convert.parseDate(${lead.myvu_enrolled_date}, 'yyyy-MM-dd HH:mm:ss')})
#else
Enrollment Date Unavailable
#end
When you say it 'breaks down', what exactly happens?
Do you get error merged in the email?
or
You get 'Enrollment Date Unavailable' all the time?
or
get blank value merged in the email?
Rajesh
Sorry should have been a bit more descriptive there! It returns the following:
$date.format('MMM dd, yyyy hh:mm aa', ${convert.parseDate(${lead.myvu_enrolled_date}, 'yyyy-MM-dd HH:mm:ss')})
We actually use the same script elsewhere, only with an opportunity level field instead of a lead level one, and it works fine sent as alerts. I am wondering if this script using a lead level field may be causing issues...
We use the script below for a different campaign, and although it is fairly different, I feel like the core operation is the same. This one has worked well so far.
#foreach($opportunity in $OpportunityList)
#if($opportunity.o_opportunity_type == "Home Loan" && $opportunity.o_pal_download_amount && $opportunity.Name == $lead.crmidentifier)
<p class="copy" style="margin: 0px;">$date.format('MMM dd, yyyy hh:mm aa',${convert.parseDate(${opportunity.o_pal_download_time},'yyyy-MM-dd HH:mm:ss')})</p>
#break
#end
#end
(Brand) new to email scripting and having a similar issue. We've got appointment times (80+) added as attributes within a datetime field. Format within the smart list view is May 7, 2016 3:00 PM. Thought it would be as easy adding a lead level token for that attribute -- {{lead.saintsseatlocation:default=]] -- but it's rendering as W3C standard for datetime, 2016-04-29 11:00:00.
I'm a little confused about what goes in email script token field and what goes in the actual email html.
Learning Java basics in an hour is probably not the best route.
We're going to re-upload the attribute as a text field in CRM, but I'd really like to solve the riddle regardless.
Hi Dan,
Something like this should work in the email script itself, but I didn't test it (I just plugged it into the script that I already had working). Always make sure the box next to the field you are using is checked within the script editor. Then, in your email, you just need the name of the email script token, like {{my.testfield}} or whatever you call it.
$date.format('MMM dd, yyyy hh:mm aa', ${convert.parseDate(${lead.saintseatlocation}), 'yyyy-MM-dd HH:mm:ss')})
Gotcha, Ryan. I am the moron who didn't check the box within the script -- but then I did check it and still no dice.
When I go to approve the email or preview against subscribers, I get 'Cannot get email content- An error occurred when procesing (sic) the email Body!' Here's where I'm at from email script, to token name to html to rendering.