SOLVED

Re: Velocity script breaking

Go to solution
Kainelson
Level 2

Velocity script breaking

Hi there, 

 

I tried to implement a simple velocity script to parse out a JSON object and it is giving me this error: 

 

Cannot get email content- <div>An error occurred when procesing the email Body! </div> <p>Lexical error: org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 2, column 1. Encountered: "\uff8a" (65418), after : "" near</p> <div><pre >#end</pre><pre >#set($parsedJson = '#set($parsedJson='+ $data+')')</pre><pre class="x-form-item-label">#evaluate($parsedJson)</pre><pre >$parsedJson['proofpoint']</pre><pre ></pre></div>

 

The JSON object I imported was:

{"proofpoint":"This is a test proof point","subject line":"test subject line","EID":"1234"}

 

and the velocity script (for online the proof point token) was: 

#set($data = ${scoutContentEngine_cList.get(0).xLROppy})
#if($data.isEmpty())
#set($data='{}')
#end
#set($parsedJson = '#set($parsedJson='+ $data+')')
#evaluate($parsedJson)
$parsedJson['proofpoint']

 

Any ideas as to why this is happening?

1 ACCEPTED SOLUTION

Accepted Solutions
SaurabhGoyal_GN
Level 4

Re: Velocity script breaking

Hi @Kainelson  - 

I faced similar issue in the past. This is due to format of the imported file. You must have imported the data using UI and file must have contained some spaces or may not be in utf-8 encoding. Just try to have proper csv with utf-8. This should work. Velocity code you posted seems perfectly fine. 

please let us know in case you still face any issue.

View solution in original post

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script breaking

Remember to use the Syntax Highlighter (“Insert/Edit code sample”) so your code is readable.

 

SanfordWhiteman_0-1714602636445.png

I edited your post this time.

 

Assuming

  1. you have a Custom Object list called $scoutContentEngine_cList
  2. the list has at least one item in it
  3. the first item in the list has a property with the API name xLROppy
  4. that property is set to the stringified JSON above

Then there’s nothing wrong with your code itself.

 

(N.B. it’s better to not have to make these assumptions from your code and to have them all laid out in your question.)

 

Questions:

  1. What is the text that appears directly after the {{my.token}} in the email body? Please show the area surrounding the {{my.token}}.
  2. Are you using Japanese in this email?
  3. Are you using Preview By List or sending a real email (not sample) to test?
  4. How have you verified the data was imported correctly?
Kainelson
Level 2

Re: Velocity script breaking

Assumptions:

  1. Yes, the custom object is $scoutContentEngine_cList
  2. The list has all 3 items in it. Proofpoint, subject, and EID. Is that what you mean?
  3. Yes, the field has the API named xLROppy
  4. It's a text field. Does it need to be a string?

Questions

  1. There is no text after the token, but there is a button (separate module). 

Screenshot 2024-05-01 at 5.56.03 PM.png

 

2. No Japanese in the email

3. I previewed by person. I looked at my record that I uploaded data on in the database.

4. I looked at the field in the custom object on my record.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script breaking

Please create a brand new mail based on the Personal Note template (i.e. to avoid confusion with any custom modules) and test with that.

 

Also include the output of a {{my.token}} with only this line in it (of course also checking off the fields in the tree on the right hand side):

${scoutContentEngine_cList}

 

SaurabhGoyal_GN
Level 4

Re: Velocity script breaking

Hi @Kainelson  - 

I faced similar issue in the past. This is due to format of the imported file. You must have imported the data using UI and file must have contained some spaces or may not be in utf-8 encoding. Just try to have proper csv with utf-8. This should work. Velocity code you posted seems perfectly fine. 

please let us know in case you still face any issue.

Kainelson
Level 2

Re: Velocity script breaking

Thank you! 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script breaking

You do not need to use UTF-8. A UTF-16LE CSV works perfectly fine (that’s Microsoft Excel’s “Unicode” format.)

 

If there are extra characters, they’re not in the text provided here by @Kainelson. So either the text in this thread is not actually what’s stored in the CO (which is why I asked specifically for the raw output of the CO list in an email) or something else is happening.