It's as simple as..
#set ($x = ${lead.FirstName.toLowerCase()})
$x.charAt(0)
An error occurred when procesing the email Rendered_Email_Velocity_Error_Area_?!
Invocation of method 'charAt' in class java.lang.String threw exception java.lang.StringIndexOutOfBoundsException: String index out of range: 0 near
and then I call the script in my email using {{my.firstinitial}}
What am I doing wrong?
(Sorry for the back and forth, I don't really have a grasp on this language yet)
hmm. I think it's a bug Kenny Elkington
It works in the email preview - according to Email Scripting » Marketo Developers anything that works in the email preview is supposed to work in an actual email, but in this case it doesn't.
Sorry.
Did you try that in the preview or in the actual email send?
It still errors at my end.
Actual, non-sample send.
Weird.. your syntax doesn't look right.
Shouldn't it contain the braces?
#set ($fi = ${lead.FirstName.toLowerCase().charAt(0)})
$fi
Even with your syntax, I'm still finding the email won't approve.
You don't need formal syntax in a #set directive unless there some syntactical confusion (like a reference right next to a constant string).
What's the error you're getting?
Well, I was able to get it to send in an actual campaign send.
But the email won't approve and the error is:
Validation Error approving testttt.kefe —
An error occurred when procesing the email Rendered_Email_Velocity_Error_Area_?!
Invocation of method 'charAt' in class java.lang.String threw exception java.lang.StringIndexOutOfBoundsException: String index out of range: 0 near
But as I'd had the email approved with my script token already included, I was able to send the test.
You should check the length of the string before trying to get an offset (index).