Unlike more traditional script development, where you can use debugging tools to step through your work, writing Velocity scripts in Marketo, particularly complex ones, can be frustrating as it's challenging to get feedback and make the little tweaks that often lead to resolving those tricky bugs. One trick that I like to use to help with this process is having a Static List of test records ready to go for use in Previewing a sample email (or Landing Page) with the misbehaving Velocity Token.
Here's the code from the previous post that goes through the (sadly uncommon) field where the Person's favorite ice cream flavor(s) information is tracked and adds a line to the email referencing it.
And this script works for our very limited use case where we only care about three flavors and aren't concerned with similar variants like "vanilla swirl" that might make our "contains" function behave incorrectly.
Now I'll do the unthinkable and purposefully break the Token by removing a quote like so:
Now, when previewing the email, I get an error like below, which is clearly indicating that there's an issue near the string "rocky" but doesn't provide much more detail beyond that.
If it was a really complex script, the debugging process could involve making a change to the Script, going back to the email, going to Preview, choosing a Person, waiting for that to load, only to find that the problem wasn't really fixed. Fortunately, to avoid this tedious process, you can use a Static List populated with test records. I put one together with ten sample records, all with ice cream preference data populated:
Then, while keeping the Token editor open in one browser tab, I choose to Preview the email in another, picking the above list in the "View By" section of the preview screen. The great part about this is that when you change the person you're viewing in the preview, by clicking one of the arrows next to their name, it refreshes both the email and the Token. So whether you're tweaking the Token, or the email (or both), checking to see if your change worked is just a single click away rather than going through the process of re-opening the email, choosing the person, etc.
After fixing the bug in the Velocity code, all I have to do is click the right arrow to go to the next person in the list and the Token changes are reflected right away and I can see that the update has resolved the mysterious error message and our ice cream message is back as it was before!
In the next blog I'll go into some more complicated use cases that will require a correspondingly more complex structured data format that will make use of some of Velocity's more advanced data functions.
... View more