Re: Velocity Scripting not Rendering

James_Walsh
Level 3

Velocity Scripting not Rendering

Hello,

I am automating emails in a Smart Campaign that is utilizing Velocity Scripted Tokens that are being populated with fields from a Custom Object. I have been running this campaign since June and just realized that about 25% of the recipients seem to be getting errors with the tokens when I look in preview mode. It is strange because it is working for the majority of the recipients but not the 25%. I looked at their custom object to insure the fields were populated, and they are. I am not sure if this is an actual error, or if it is just something wrong with Marketo's Preview Instance.

I've attached screenshots to show when the tokens work, and when I get an error. Any explanation?

Tags (1)
7 REPLIES 7
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting not Rendering

Please move the thread to Products‌. Move link will be at the right. This isn't a support space.

You also need to provide (highlighted) code, dumps of your object data, and examples of the errors -- there isn't enough to go on here.

James_Walsh
Level 3

Re: Velocity Scripting not Rendering

Here is an example of one of the Tokens Scripting. I don't think it has to do with the scripting as it is working for a number of recipients, just not all.

#set($total = $number.currency(${jHIMPolicyFeed_cList.get(0).vitalityRefundAmount}))
#set($stringLength = $total.length() - 0)
#set($totalb = $total.substring(0,$stringLength))
${totalb}

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting not Rendering

Please highlight the code using the Advanced Editor's syntax highlighter, like so:

pastedImage_1.gif

Select Java as the language, as it's closest to Velocity.

Your code, as far as I can read it without highlighting, depends on:

  • $jHIMPolicyFeed_cList being non-empty
  • the first item in $jHIMPolicyFeed_cList having a non-empty, non-null property vitalityRefundAmount

Ensure those conditions are met (by dumping the object list) when the output doesn't match your goals.

It's vanishingly unlikely that the problem is with the Velocity engine as opposed to your code + data.

James_Walsh
Level 3

Re: Velocity Scripting not Rendering

#set($total = $number.currency(${jHIMPolicyFeed_cList.get(0).vitalityRefundAmount}))
#set($stringLength = $total.length() - 0)
#set($totalb = $total.substring(0,$stringLength))
${totalb}

Can you further explain dumping the object list and the Velocity Engine. 

I just find it strange it works for some recipients but not others even though the data is identical.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting not Rendering

Can you further explain dumping the object list and the Velocity Engine.

"Dumping the object list" = looking at the raw data of $jHIMPolicyFeed_cList.

#foreach( $item in $jHIMPolicyFeed_cList )
#foreach( $kv in $item.entrySet() )
${display.alt($kv.getValue().class,"null")} ${kv.getKey()} = ${kv.getValue()}
#end
#end‍‍‍‍‍

"the Velocity Engine" = the Velocity core logic and built-in tools.  You would have to do a lot of work to prove there's something malfunctioning within this app that's been used for almost 20 years. Not to say it doesn't have bugs (I logged one last month) but one shouldn't start by pointing the finger at Velocity itself.

I just find it strange it works for some recipients but not others even though the data is identical.

I doubt the data is actually identical.

James_Walsh
Level 3

Re: Velocity Scripting not Rendering

When I say identical I mean the field that the script is pulling from that works for some contacts is populated in the same manner as the contacts I am getting errors on. I am confused as why there would be a break. I cannot understand why it populates for some and errors for others. Did my screenshots I shared earlier provide any insight?

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting not Rendering

Dump your object list, as shown above. It's not going to show the same data, I guarantee it.