Tokens within a velocity script

Brian_McLaughli
Level 1

Tokens within a velocity script

Can I include a token, not a SalesForce object but a local token, within a velocity script?

I have a datetime token that I use to trigger the flow.  I want to format this token into something more human readable to include within my email.

I've tried something like this:

#set($formattedDate = $date.format("yyyy-MM-dd", ${{my.arbitrary_date}}))

${formattedDate}

where, {{my.arbitrary_date}} is a local token in the same Marketo project.

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Tokens within a velocity script

No, not a text token. But another Velocity token, sure. This is pretty standard practice in VTL-heavy environments, since all inserted Velocity tokens share a global context.

----BEGIN VTL {{my.vtl_token_1}}----

#set( $mydate = "2017-03-01" )

----END VTL {{my.vtl_token_1}}----

----BEGIN VTL {{my.vtl_token_2}}----

#set( $formattedDate = $date.format("yyyy-MM-dd", $mydate) )

----END VTL {{my.vtl_token_2}}----

Brian_McLaughli
Level 1

Re: Tokens within a velocity script

Thank you, Sanford.

What I'm trying to avoid is have multiple local tokens that represent the date the flow is started, one date token that is used in the flow itself, and one text token that is a human readable version of the date token and is inserted in the body of the email. Can you think of a way around this?  Can I access the date that the flow is to start from within Velocity?

SanfordWhiteman
Level 10 - Community Moderator

Re: Tokens within a velocity script

OK, if you're using a date token in the Smart List itself, that has to be a {{my.token}} of the Date type.  Velocity/Email Script type tokens can't be used there.

So in this case, you do need two tokens. I would store the date in a Velocity token because I like the display to be flexible, for example based on time zone and locale) but either way you're going to have to redundantly put the date in two places.