Spript Token Outputing Velocity Code Instead of Expected Text

Marissa_Bobitt-
Level 1

Spript Token Outputing Velocity Code Instead of Expected Text

Hi All,

I'm a brand new Velocity developer (i.e, I was volunteered) and have come across my first hiccup. I first want to thank Sanford Whiteman​ for his fantastic blog posts and replies. I ended up Frankenstein-ing this bit of code from a few of his posts. While it works for actual names it's failing to output the fallback default. Instead I'm getting "$name.substring(0,1).toUpperCase()$name.substring(1).toLowerCase()".

#set($name = $lead.FirstName)

#if( $lead.FirstName.isEmpty() )

  Friend

#else

  $name.substring(0,1).toUpperCase()$name.substring(1).toLowerCase()##

#end

All names are uppercase in the db. This code is make sure the first character stays capitalized and the rest is lowercase.

Names pass through just fine which is 99.5% of our lists but that last .5% makes me itch. Other Info; I'm testing this with send sample and (thankfully) haven't seen anything in the wild but I expect it to work just like the oob {{lead.FirstName:defualt=Friend}} token.

Thanks in advanced for any suggestions or solutions!

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Spript Token Outputing Velocity Code Instead of Expected Text

Thanks for reading my Velocity content! Much, much more to come, once I put the finishing touches on my some extra-long drafts.

Your code is fine, but a trifle repetitive. You already have $name extracted, so use it:

#set($name = $lead.FirstName) 

#if( $name.isEmpty() ) 

  Friend 

#else 

  $name.substring(0,1).toUpperCase()$name.substring(1).toLowerCase()## 

#end 

The problem is surely that you're using Send Sample. You can't use samples to test Velocity unless there's no dependency on $lead at all (obviously not the case here). Use real emails or Preview-By-List in the UI (create a static list and add test leads to it).

P.S. toUpperCase and toLowerCase are not decomposition-aware, so they're not as safe as people assume when dealing with accented Latin-1 characters. This affects Java as well, so it's not a Velocity-specific or Marketo-specific problem, but it is real. If you don't know what this all means, wait for an upcoming post.