Troubles when using Javascript within Velocity?

Ken_Soldink
Level 2

Troubles when using Javascript within Velocity?

I've been trying to implement Sanford Whiteman‌'s post "Use Javascript within Velocity" from late 2017 to utilize Javascript in an Email Script Token, and when following the example verbatim, instead of outputting the Lead's firstname

Kenneth

playfully as

K e N n E t H

, the actual Velocity code is output in the email:

$JSEngine.put("lead", $lead) $JSEngine.get("spacedOutInJS")

Attached are screenshots showing:

  • the token script - named "ai_trk_test" (20190808_104120_msedge_CompassionateTuraco_938x794.png),
  • the email draft with {{my.ai_trk_test}} included (20190808_104357_msedge_SnowBuzzard_815x516.png), and
  • previewing the email as a Person with Kenneth as first name 20190808_104600_msedge_ImmenseBluet_1052x680.png)

Am I missing something here?

Kenneth Soldink

4 REPLIES 4
Ken_Soldink
Level 2

Re: Troubles when using Javascript within Velocity?

Just came across this https://nation.marketo.com/docs/DOC-6953 which probably means that this is not supported anymore...

SanfordWhiteman
Level 10 - Community Moderator

Re: Troubles when using Javascript within Velocity?

Correct, this and many other advanced techniques were disabled at that time. 

In fairness, though, this is more of a frill (as opposed to other important techniques that have no equivalent now). What exactly are you trying to do with your data that required JS?

Ken_Soldink
Level 2

Re: Troubles when using Javascript within Velocity?

I was originally aiming to generate a Base64 string from small JSON string that contains some default and custom fields, as well as a timestamp, to append onto links. I can go a different route, but this was nice as it afforded my endpoint some simplicity in interpreting the string.

SanfordWhiteman
Level 10 - Community Moderator

Re: Troubles when using Javascript within Velocity?

Does Rhino even support btoa?

Anyway, Bae64 used to be possible without calling the JS engine, but that method got thrown out w/the bathwater as well.