Velocity working in preview mode, not in sample mail
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}"))
#else
#set( $val = $lead.PostalCode.substring($start,$end))
##set( $postalInt = $convert.toNumber("0${val}"))
#end
${val}
The code is working in preview mode ( View By : Person ), but when i send a test mail I receive :
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???