AnsweredAssumed Answered

Velocity working in preview mode, not in sample mail

Question asked by Franky Ruysschaert on Sep 12, 2019
Latest reply on Sep 12, 2019 by Sanford Whiteman

Hi I have the following velocity script that takes, the post code from the lead. If the length of the postalcode is 4 it is converted to a number for further use, if the length is different from 4 ( in which all cases it is 6 ) , i have to take the first 4 characters, and convert them to a number.

#set( $start = 0 )
#set( $end = 4 )
#set( $postalCode = ${lead.PostalCode} )
#if ( $postalCode.length().equals(4) )
#set( $postalInt = $convert.toNumber("0${postalCode}"))
#set( $val = $lead.PostalCode.substring($start,$end))
##set( $postalInt = $convert.toNumber("0${val}"))




The code is working in preview mode ( View By : Person ), but when i send a test mail I receive : 


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: 4 near


What is wrong here???