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 ><p><span style="font-family: Verdana;">#set( $productArr = ["1","2","3"] )</pre><pre >#if( !$display.alt($CO_c["product"],"").isEmpty())</pre><pre class="x-form-item-label">#set( $productArr[] = $CO_c["product"].split("|") )</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]
Solved! Go to Solution.
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.
Hi Jay,
I think there are some syntax errors. Just refer to earlier post, you'll get your answer.
xx
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
[|]
And also
Pretty lost as to what you're trying to accomplish here. Can you please describe the business goal without code?
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.
There's a space character, too, on either side of the pipes in your example.
I'm going to ignore the whitespace, but please be precise when giving example data.
All you need here is
#set( $productParts = $CO_c.product.split("[|]") )
Note split() returns an Array, not a ArrayList, though that shouldn't make a difference in your case.
single object product value is a|b|c added for testing.
#if(!$display.alt($CO_c["product"],"").isEmpty())
#set( $productParts = $CO_c.product.split("[|]") )
#end
$productParts[0]
$productParts[1]
$productParts[2]
Although, I am not getting any error but display value is not as desired. It print as a string $productParts[1] and so on.
That code works fine if indeed the key named
product
on a map named
$CO_c
is set to the string
1|2|3
If you're using the wrong key name, sending a sample, or any other case where $CO__c doesn't have a key named product, then you would see the literal code output instead (that's what Velocity outputs by default when values are null).
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.