Email scripting lexical error | Community
Skip to main content
Level 9
March 29, 2017
Solved

Email scripting lexical error

  • March 29, 2017
  • 1 reply
  • 3592 views

Hi guys

I'm struggling with an email script and I'm hoping that someone can help me debug. It seems pretty straightforward...or so I thought!

I've replaced our domain and the field name with placeholders, but otherwise this is how the script appears:

#set($HeaderImageURL = "letsgo.brand/rs/110-AIL-152/images/Australia-600x350.jpg")

#if(${lead.fieldname} == "Australia")

    #set($HeaderImageURL = "letsgo.brand/rs/110-AIL-152/images/Australia-600x350.jpg")

#elseif(${lead.fieldname} == "Burgundy")

    #set($HeaderImageURL = "letsgo.brand/rs/110-AIL-152/images/Burgundy-600x350.jpg")

#elseif(${lead.fieldname} == "Costa Rica")

    #set($HeaderImageURL = "letsgo.brand/rs/110-AIL-152/images/Costa-Rica-600x350.jpg")

#elseif(${lead.fieldname} == "India")

#set($HeaderImageURL = "letsgo.brand/rs/110-AIL-152/images/India-600x350.jpg")

#elseif(${lead.fieldname} == "Japan")

#set($HeaderImageURL = "letsgo.brand/rs/110-AIL-152/images/Japan-600x350.jpg")

#elseif(${lead.fieldname} == "Namibia")

#set($HeaderImageURL = "letsgo.brand/rs/110-AIL-152/images/Namibia-600x350.jpg")

#elseif(${lead.fieldname} == "Peru")

  #set($HeaderImageURL = "letsgo.brand/rs/110-AIL-152/images/Peru-600x350.jpg")

#elseif(${lead.fieldname} == "USA")

  #set($HeaderImageURL = "letsgo.brand/rs/110-AIL-152/images/USA-600x350.jpg")

#else

#end

$HeaderImageURL

The email script token is called "{{my.Header_Image}}". In the HTML itself, the image looks like this:

<img src="{{my.Header_Image}}" width="600" border="0"  class="deviceWidth" style="display:block;border-width:0;-ms-interpolation-mode:bicubic;"/>

I don't even get an error when I send a sample email, or a live deployment. The email soft bounces, and I get this error in the activity log:

System send failure: Velocity transform failed: ; The nested exception is: <cntrl char>org.apache.velocity.exception.ParseErrorException: Lexical error, Encountered: " " (160), after : "" at *unset*[line 279, column 40]

I know that's referring to the Velocity script, but I can't see the error in my code. Any ideas?

Thanks, Phil

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Suspect you have an extra whitespace (charCode 160) character somewhere in there. It probably didn't transfer to the forum post, though.

I would do it like this anyway, easier to maintain (you probably knew I was going to do this!):

#set( $HeaderImageURLs = {

  "Australia" : "Australia-600x350.jpg",

  "Burgundy" : "Burgundy-600x350.jpg",

  "Costa Rica" : "Costa-Rica-600x350.jpg",

  "India" : "India-600x350.jpg",

  "Japan" : "Japan-600x350.jpg",

  "Namibia" : "Namibia-600x350.jpg",

  "Peru" : "Peru-600x350.jpg",

  "USA" : "USA-600x350.jpg",

  "*" : "Australia-600x350.jpg"

} )

#set( $HeaderPath = "letsgo.brand/rs/110-AIL-152/images/" )

#set( $HeaderImageURL = $HeaderImageURLs["*"] )

#set( $HeaderImageURL = $HeaderImageURLs[$lead.fieldname] )

${HeaderPath}${HeaderImageURL}

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
March 29, 2017

Suspect you have an extra whitespace (charCode 160) character somewhere in there. It probably didn't transfer to the forum post, though.

I would do it like this anyway, easier to maintain (you probably knew I was going to do this!):

#set( $HeaderImageURLs = {

  "Australia" : "Australia-600x350.jpg",

  "Burgundy" : "Burgundy-600x350.jpg",

  "Costa Rica" : "Costa-Rica-600x350.jpg",

  "India" : "India-600x350.jpg",

  "Japan" : "Japan-600x350.jpg",

  "Namibia" : "Namibia-600x350.jpg",

  "Peru" : "Peru-600x350.jpg",

  "USA" : "USA-600x350.jpg",

  "*" : "Australia-600x350.jpg"

} )

#set( $HeaderPath = "letsgo.brand/rs/110-AIL-152/images/" )

#set( $HeaderImageURL = $HeaderImageURLs["*"] )

#set( $HeaderImageURL = $HeaderImageURLs[$lead.fieldname] )

${HeaderPath}${HeaderImageURL}

Level 9
March 30, 2017

Thanks so much! Works like a charm.

Still unsure why it didn't work the first time, but yours is much more elegant.

Thanks!