4 Replies Latest reply on Jun 1, 2016 8:02 AM by d89f64cd7754e9b28f8bc4ec66661dfbfda992ec

    Script error thrown from method 'substring'?

      I'm trying to create a quick token to capitalize a lead's first name. I referenced this conversation: https://nation.marketo.com/message/83535#comment-83535

      The code is:

      #set($name = ${lead.FirstName})

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

       

      And I checked the box next to First Name.

      it's dropped into an email as: {{my.FName Capitalized:default=Hello}},

       

      At first blush, it seemed to work. But now I'm getting an error whenever I try to save the email I've placed it on:

       

      An error occurred when procesing the email Rendered_Email_Velocity_Error_Area_?!

      Invocation of method 'substring' in class java.lang.String threw exception java.lang.StringIndexOutOfBoundsException: String index out of range: 1 near

      ?

       

      This might be a little beyond my skill level. Any suggestions? Or maybe another way to do this to avoid the error? I know we want some backend stuff that checks names, but that's for later. This is our quick fix for the time being.