Our subscription expiration date is in a field on the Account object. I have a subscription expiration reminder email that references that date via a field token; however, the format of the date is yyyy-mm-dd, but I want it to be mm-dd-yyyy. I tried to create a My email token with a velocity script like '$date.format('MMM dd, yyyy aa', ${convert.parseDate(${company.CRD__c}), 'yyyy-MM-dd HH:mm:ss')})', but that fails when I try to approve the email and it appears that only fields on the opportunity and lead objects can be referenced in the script. Is the only workaround to add the subscription expiration date on the lead object and use a formula field to update it from the Account object field?
You can access account fields, like ${lead.Account_Owner_First_Name}, just don't reference them in your script like {{account.account owner}}.
Thanks Nicholas!
There are numerous posts and docs about reformatting the value in a date field, but I was a little confused since I've never used Velocity scripts before. I was trying to use the Marketo token convention for the field name and your response helped me realize that the Velocity script is prefacing the field API name with the Marketo object name such as 'lead' which includes the fields that are associated with the 'company' category in Marketo tokens.
So for anyone reading this in the future, if you want to convert a date field default format from 'yyyy-mm-dd' to 'MMM dd, yyyy', below is the velocity script to ad to your email token in My Tokens, just change the field API name to whichever field you need.
$date.format('MMM dd, yyyy', $convert.parseDate(${lead.CRD__c}, 'yyyy-MM-dd'))
I'm glad that helped.
Also, for anyone else reading this: SimpleDateFormat (Java Platform SE 7 )
I think this is a really useful guide to date formats worth bookmarking.