-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Sep 1, 2016 11:19 PM (in response to Nick Koutsioulis)3 of 3 people found this helpfulWhen you first parse the Date from the string (inbound) include the timezone, and remember to include the time itself (you don't have it in your format pattern).
Instantiate the output timezone -- in the below snippet, in and out are the same -- and format the new string (outbound) with that timezone.
#set( $inTimeZone = $date.getTimeZone().getTimeZone('Australia/Sydney') ) #set( $outTimeZone = $date.getTimeZone().getTimeZone('Australia/Sydney') ) #set( $locale = $date.getLocale() ) #set( $myDate = $convert.parseDate($lead.pexa_callbacktime,'MM-dd-yy HH:mm:ss',$locale,$inTimeZone) ) ${date.format('MMMM dd, yyyy hh:mm a z',$myDate,$locale,$outTimeZone)}
-
Re: Set local timezone using Velocity scripts
Jamie LewisSep 2, 2016 10:18 AM (in response to Sanford Whiteman)
Thanks Sanford, this is great!
-
Re: Set local timezone using Velocity scripts
Nick Koutsioulis Sep 2, 2016 11:43 PM (in response to Sanford Whiteman)Thanks Sanford, this has worked!
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Sep 3, 2016 12:04 AM (in response to Nick Koutsioulis)Great. I'm going to do a short blog post on this as it seems to frequently be done incorrectly (people think their Velo tz and instance/Admin tz are the same).
-
Re: Set local timezone using Velocity scripts
Matthew Varone Nov 17, 2016 1:41 PM (in response to Sanford Whiteman)Im sorry to ask a silly question but how to I apply this to a token on a landing page
Thanks
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Nov 17, 2016 1:57 PM (in response to Matthew Varone)In an LP, where Velocity is not available, you can use a tz-aware library like Moment-Timezone.
-
-
-
-
Re: Set local timezone using Velocity scripts
fdb29c35d6e1c4df53c3667b8088cef98869c719 Dec 21, 2016 8:20 PM (in response to Sanford Whiteman)Hi Sanford,
I'm looking to solve the same problem so our company can send a reminder email regarding a training. I'm not sure where I put this script. Is it in the email code header? Or do you add this to a snippet?
Also, I'm guessing I just need to adjust the '$lead.pexa_callbacktime' to the corresponding token field that I would have in this email 'company.Scheduled Training Date'.
#set( $inTimeZone = $date.getTimeZone().getTimeZone('Australia/Sydney') )
#set( $outTimeZone = $date.getTimeZone().getTimeZone('Australia/Sydney') )
#set( $locale = $date.getLocale() )
#set( $myDate = $convert.parseDate($company.Scheduled Training Date,'MM-dd-yy HH:mm:ss',$locale,$inTimeZone) )
${date.format('MMMM dd, yyyy hh:mm a z',$myDate,$locale,$outTimeZone)}
Cheers
Travis
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Dec 21, 2016 9:50 PM (in response to fdb29c35d6e1c4df53c3667b8088cef98869c719)I'm looking to solve the same problem so our company can send a reminder email regarding a training. I'm not sure where I put this script. Is it in the email code header? Or do you add this to a snippet?
Neither: you create a new Email Script token and the code goes in the editor (left-hand side).
In the tree on the right-hand side, remember to check the boxes next to all fields you want to reference in the code -- in your case the Scheduled Training Date. You should drag the field into the editor to find out the VTL (Velocity) name for the field. It won't be the same as the normal token name because it can't have spaces. For example, {{lead.First Name}} as a normal token is $lead.FirstName in VTL.
Then the name of the Email Script token goes into the email using regular {{my.token}} syntax, for example {{my.velocity_training_date}} or whatever you call it.
-
Re: Set local timezone using Velocity scripts
fdb29c35d6e1c4df53c3667b8088cef98869c719 Dec 22, 2016 3:17 PM (in response to Sanford Whiteman)I've set up the Email Script token as below. It re-arranges the date properly but still reverts to a different time zone.
Training date in salesforce:
24/05/2016 2:30PM
What shows up with the email token:
23 May, 2016 11:30 PM EST
#set( $inTimeZone = $date.getTimeZone().getTimeZone('Australia/Sydney') )
#set( $outTimeZone = $date.getTimeZone().getTimeZone('Australia/Sydney') )
#set( $locale = $date.getLocale() )
#set( $myDate = $convert.parseDate($lead.Scheduled_Training_Date__c,'yy-MM-dd HH:mm',$locale,$inTimeZone) )
${date.format('dd MMMM, yyyy hh:mm a z',$myDate,$locale,$outTimeZone)}
Any suggestions?
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Dec 22, 2016 4:35 PM (in response to fdb29c35d6e1c4df53c3667b8088cef98869c719)Are you in Sydney?
-
Re: Set local timezone using Velocity scripts
fdb29c35d6e1c4df53c3667b8088cef98869c719 Dec 22, 2016 4:38 PM (in response to Sanford Whiteman)Yes.
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Dec 22, 2016 5:10 PM (in response to fdb29c35d6e1c4df53c3667b8088cef98869c719)K, just checking first! I'm on my phone so can't verify the rest. Let me respond later or tomw. I suspect (well, know) that the stored value has a different offset than what's displayed in SFDC, so you have to account for that.
-
-
-
-
-
-
Re: Set local timezone using Velocity scripts
Victoria Chu Jan 8, 2019 1:02 PM (in response to Sanford Whiteman)Hi Sanford Whiteman I'm looking to create an email velocity script that will display the stored date/time field in the U.S. pacific time zone.
Marketo support says date time field tokens populate with Central time regardless of the location the Marketo Instance is set. This is due to how field values are stored in Marketo.
Would I be able to follow the format of the solution you've provided and swap out any Australia/Sydney reference to US/Pacific? Thank you!
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Jan 8, 2019 1:48 PM (in response to Victoria Chu)This is due to how field values are stored in Marketo.
(It's actually not because of the way they're stored, but the behavior is known in any case.)
Would I be able to follow the format of the solution you've provided and swap out any Australia/Sydney reference to US/Pacific? Thank you!
Yes, the time zone name is
America/Los_Angeles
-
Re: Set local timezone using Velocity scripts
Victoria Chu Jan 8, 2019 1:58 PM (in response to Sanford Whiteman)Thank you Sanford Whiteman for the quick response!
This is the velocity script I'm now testing - the particular lead I'm previewing the email at has a create at date/time of Jan 8, 2019 10:22 AM. The velocity script is returning the value as Jan 8, 2019 12:22:00. What did I do wrong?
#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') )
#set( $outTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') )
#set( $locale = $date.getLocale() )
#set( $myDate = $convert.parseDate(${lead.Created_At},'yyyy-MM-dd HH:mm:ss',$locale,$inTimeZone) )
${date.format('yyyy-MM-dd HH:mm:ss',$myDate,$locale,$outTimeZone)}
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Jan 8, 2019 2:58 PM (in response to Victoria Chu)Can I ask that you go back and highlight the code using the Advanced Editor's syntax highlighter? That makes it readable.
Also please take the curly braces out from ${lead.Created_At}. Use the simple notation $lead.Created_At. That isn't causing the problem but can cause other problems down the line.
When you simply print the String
$lead.Created_At
in Velocity, do you see
2019-01-08 10:22:00
?
-
Re: Set local timezone using Velocity scripts
Victoria Chu Jan 8, 2019 2:33 PM (in response to Sanford Whiteman)#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') ) #set( $outTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') ) #set( $locale = $date.getLocale() ) #set( $myDate = $convert.parseDate($lead.Created_At,'yyyy-MM-dd HH:mm:ss',$locale,$inTimeZone) ) ${date.format('yyyy-MM-dd HH:mm:ss',$myDate,$locale,$outTimeZone)}
If I simply print the string
$lead.Created_At
In velocity I see
2019-01-08 12:22:00
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Jan 8, 2019 2:39 PM (in response to Victoria Chu)1 of 1 people found this helpfulSorry, the $inTimeZone should be America/Chicago, the $outTimeZone America/Los_Angeles.
-
Re: Set local timezone using Velocity scripts
Victoria Chu Jan 8, 2019 3:38 PM (in response to Sanford Whiteman)Thank you it worked beautifully! Curious to your point about removing the {brackets} surrounding the fields. Why would it cause problems in the velocity script? We have that in place for all of our script and want to make sure they continue to function properly.
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Jan 8, 2019 4:36 PM (in response to Victoria Chu)Curious to your point about removing the {brackets} surrounding the fields. Why would it cause problems in the velocity script? We have that in place for all of our script and want to make sure they continue to function properly.
This blog post of mine should explain it: Velocity ${formal.notation} invites syntax errors: use it wisely
-
Re: Set local timezone using Velocity scripts
Victoria Chu Jan 8, 2019 4:59 PM (in response to Sanford Whiteman)Update Sanford Whiteman - When I preview the email using a lead record, the script runs correct. However, in a real trigger/batch campaign, the script fails on the email, showing up blank. Can you think of why this would happen? Thanks.
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Jan 8, 2019 5:41 PM (in response to Victoria Chu)Showing up blank when the token exists is very rare. You should at least see an error dump.
Are you certain the token is in the folder hierarchy and the email is approved?
-
Re: Set local timezone using Velocity scripts
Victoria Chu Jan 9, 2019 9:46 AM (in response to Sanford Whiteman)-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Jan 9, 2019 5:26 PM (in response to Victoria Chu)And if you append another line to the token that just outputs some dummy text?
-
Re: Set local timezone using Velocity scripts
Victoria Chu Jan 11, 2019 3:21 PM (in response to Sanford Whiteman)Sanford Whiteman I had put the script tokens in the program where the centralized alert email lives, not in the highest level of folder that houses all the program where the smart campaigns live. This explains perfectly why the preview worked but not the real send. Thanks for your help!
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Jan 11, 2019 3:31 PM (in response to Victoria Chu)Great!
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Re: Set local timezone using Velocity scripts
Mark Wallace Jul 3, 2018 4:09 AM (in response to Nick Koutsioulis)Hello All
Just discovered this and found I can put a webinar into the contacts local timezone using the person time zone field value. Fantastic.
Wanted to check is it possible to put the local campaign tokens into the velocity script. Im currently including the webinar times by putting the webinar times into a field, when they are already in a local token.
If I could put the webinar start time token into the script that would make my day.
thanks for this
-
Re: Set local timezone using Velocity scripts
Sanford Whiteman Jul 3, 2018 10:19 AM (in response to Mark Wallace)What do you mean by "local campaign tokens"? The built-in {{campaign.tokens}}?
-