Velocity email script split data based on delimiter "|" | Community
Skip to main content
Jay_sandbox_Sin
New Participant
December 1, 2020
Solved

Velocity email script split data based on delimiter "|"

  • December 1, 2020
  • 2 replies
  • 4628 views

In CO table, one of the field has product value in below format

product =  productname | productimage | productcode

My pain point is to split the data but I am getting below issue

Cannot get email content- <div>An error occurred when procesing the email Body! </div> <p>Encountered "]" near</p> <div><pre >&lt;p&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;#set( $productArr = [&quot;1&quot;,&quot;2&quot;,&quot;3&quot;] )</pre><pre >#if( !$display.alt($CO_c[&quot;product&quot;],&quot;&quot;).isEmpty())</pre><pre class="x-form-item-label">#set( $productArr[] = $CO_c[&quot;product&quot;].split(&quot;|&quot;) )</pre><pre >$productArr[1]</pre><pre >$productArr[2]</pre></div>

 

I have tried below sample VTL code.

##Using split("|") function to seprate the data sets #set( $productArr = ["1","2","3"] ) #if( !$display.alt($CO_c["product"],"").isEmpty()) #set( $productArr[] = $CO_c["product"].split("|") ) $productArr[1] $productArr[2] $productArr[3]
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

Hi @sanfordwhiteman 

 

CO and keyname all are correct. please refer below screenshot.

Although, In Marketo last we saw issue deleting the CO even after CO was not used anywhere in Marketo. After that Marketo support team fixed that issue. But, now in this case I am not sure if I should reach out to support team because they do not support coding part.


I'm referring to the Velocity name of the object list and key.

 

Not the API name, that must be considered completely different (even if it is closely related).

 

You only know the Velocity name by dragging it onto the Velocity Script Editor canvas.

2 replies

SanfordWhiteman
New Participant
December 1, 2020

There's a syntax error. You're missing an #end.

 

But even when you fix that, it still won't do what you expect, because the argument you're passing to split() is a regex pattern, not a string. As such, the pipe needs to be escaped as

[|]

 

SanfordWhiteman
New Participant
December 1, 2020

And also

  • you're redeclaring $productArr quite confusingly
  • there's another fatal syntax error: $productArr[] is not valid Velocity, it would just be $productArr

Pretty lost as to what you're trying to accomplish here. Can you please describe the business goal without code?

Jay_sandbox_Sin
New Participant
December 2, 2020

In custom objects, one object field data is being pushed with this combination "productname | productimage | promocode

Business goal is to display product name,  image and promo code details in the email. So, splitting the data based on delimiter (|) and used the VTL token in email to get the output.

Employee
December 1, 2020

Hi Jay,

 

I think there are some syntax errors.  Just refer to earlier post, you'll get your answer.

https://nation.marketo.com/t5/Product-Discussions/Velocity-Splitting-a-string-into-an-array/m-p/144642#M99410

 

xx