Velocity script breaking | Community
Skip to main content
Level 2
May 1, 2024
Solved

Velocity script breaking

  • May 1, 2024
  • 2 replies
  • 2825 views

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?

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 SaurabhGoyal_GN

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.

2 replies

SanfordWhiteman
Level 10
May 1, 2024

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

 

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?
KainelsonAuthor
Level 2
May 2, 2024

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). 

 

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
May 2, 2024

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
SaurabhGoyal_GNAccepted solution
Level 4
May 2, 2024

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.

KainelsonAuthor
Level 2
May 2, 2024

Thank you!