SOLVED

Re: Email Script Tokens for Real Beginners

Go to solution
Allison_Proehl
Level 4

Email Script Tokens for Real Beginners

Does anyone have really beginner-level resources for learning how to do email script tokening? I've never done it before and feel like I missing out on some really cool/useful stuff. 

One of the problems I'm trying to solve is:

If the lead picks "Consultant A" then show "Schedule Consultation" (with a hyperlink to Consultant A's calendar.)

then,

If the lead picks "Consultant B" then show "Schedule Consultation" (with a hyperlink to Consultant B's calendar.)

Lastly, 

if the lead picks "Unsure" then show "Schedule Consultation" (with a hyperlink to Consultant A's calendar, b/c they are our default.)

I've read a couple of Sanford Whiteman‌ blogs, and I feel like they are way over my head.

All help appreciated!

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script Tokens for Real Beginners

Something I mention in my Velocity classes is that the language was originally created as an easier-to-use, faster-to-market way to write code in a Java shop. Meaning it was still expected to be used by developers -- maybe very junior ones, but not folks who had zero interest in/exposure to datatypes and OO ideas.

It's apparent from the Velocity Tools docs that you're supposed to know what an int[] is (an array of int primitives) and there's no special explanation of stuff like that. Even when introducing the very simple #foreach/#end structures, there's mention of Collections and Iterators, which you could skip over and still write good code but there's a clue to a wider world.

Velocity does a ton of automatic type juggling for you that Java would never do, making it without a doubt exponentially faster for writing emails, web pages, or other text output. But if you ignore the Java underpinnings, you'll be  confused when you run into a fatal error thrown from Java-land (like aStringIndexOutOfBoundsException).

I'm planning some short(ish) posts on the Marketo blog to deal with individual technical details of Velocity. They won't be dumbed-down, though, there's just no way to do that.

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script Tokens for Real Beginners

Well, learning Velocity is far from an overnight thing.

The reason VTL can seem obscure is... it's real code! Velocity is a real language running on top of Java. (And don't listen to anyone who says it's easy, that's a sign that they aren't a power user.)

As Velocity is very verbose, you want to use collection-centric code.

  • create a collection (i.e. Map) holding your options
  • your consultant field (I'll call it ChosenConsultant since I don't know what the real name is in your instance) is the lookup key, and the URL is the value

#set( $consultantLinks = {
"Consultant A" : "www.example.com/bookwithA",
"Consultant B" : "www.example.com/bookwithB",
"Unsure" : "www.example.com/bookGeneric"
} )
<a href="https://${consultantLinks[$lead.ChosenConsultant]}">Click to schedule</a>
Michael_Florin
Level 10

Re: Email Script Tokens for Real Beginners

Although I am using Email Scripts for years, I still consider myself a beginner - just because I don't speak Java. I kinda understand what Sandford is telling you with the "collection", so I would copy the script, file it somewhere in my own script library, then test it, love it, use it, and thank him sincerely.

Couple of tips: 

  • Start easy. Even a "simple" script with If, ElseIf and Else can bring you a solution to a problem you would never be able to solve otherwise. For example: Build a salutation string for some languages.
  • Create a static list to be used in email previewing. The persons on the list can be just made up persons, so you can add whatever field values to them that your scripts are using.

2019-09-12 11_42_42-Window.jpg

  • When testing your scripts, always do your final test in a live email send (not a sample), and if your script outputs links, click them. URLs in scripts are tricky beasts.

And no, there are no beginner-level resources out there. If there were, I would have found them. I googled this stuff A LOT. But you're right: If you don't know about scripts, you're missing out. But moving in tiny steps from simple to complex will get you somewhere eventually. We have like ten Marketo users in our organization who are comfortable editing their own scripts, understand them and come up with ideas to build new ones. And none of them are developers.

SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script Tokens for Real Beginners

Something I mention in my Velocity classes is that the language was originally created as an easier-to-use, faster-to-market way to write code in a Java shop. Meaning it was still expected to be used by developers -- maybe very junior ones, but not folks who had zero interest in/exposure to datatypes and OO ideas.

It's apparent from the Velocity Tools docs that you're supposed to know what an int[] is (an array of int primitives) and there's no special explanation of stuff like that. Even when introducing the very simple #foreach/#end structures, there's mention of Collections and Iterators, which you could skip over and still write good code but there's a clue to a wider world.

Velocity does a ton of automatic type juggling for you that Java would never do, making it without a doubt exponentially faster for writing emails, web pages, or other text output. But if you ignore the Java underpinnings, you'll be  confused when you run into a fatal error thrown from Java-land (like aStringIndexOutOfBoundsException).

I'm planning some short(ish) posts on the Marketo blog to deal with individual technical details of Velocity. They won't be dumbed-down, though, there's just no way to do that.

Allison_Proehl
Level 4

Re: Email Script Tokens for Real Beginners

Thank you for putting it more in perspective Sanford.  I'm definitely sure its no easy topic to learn, but a worthwhile one. 

I'll keep an eye out for your blogs and maybe when I become a little more experienced I can come back and decipher them!