SOLVED

Re: Velocity Dynamic Content Sorting

Go to solution
Jayant_Singh
Level 3

Re: Velocity Dynamic Content Sorting

I have added the code in three ways

1. Full code at top after debug no change in previous email design.

2. Both end statement at last after debug nothing display.

3. Putting both end statement before output the ${outputName} and got below design

Jayant_Singh_0-1590177290207.png

 

Jayant
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Dynamic Content Sorting

I'm not sure you're putting the code in the right place.

 

If you put that code in a Velocity token (in Script Editor) it'll give you a full debug dump of all the fields in the given list, with their names, values (or null) and datatypes.

Jayant_Singh
Level 3

Re: Velocity Dynamic Content Sorting

This is the one script product name where I added the code at the top.

 

<html>
<body>
<table>
#set( $coList = $pro_cList )
#foreach( $record in $coList )
#foreach( $kv in $record.entrySet() )
{kv.getKey()} ${display.alt($kv.getValue().class,"")} ${display.alt($kv.getValue(),"null")}
#end
#end
## start product name select
<tbody>
#set( $DEFAULT_Product = "No item in list." )
<tr>
#if( $pro_cList.isEmpty() )
#set( $outputName = $DEFAULT_Product )
#else
#foreach( $pro_c in $sorter.sort($pro_cList, "date:desc") )
#if( !$display.alt($pro_cList["productName"],"").isEmpty() )
#set( $outputName = $pro_c["productName"] )
#break
#end
#end
#set( $outputName = $display.alt($outputName, $DEFAULT_Product) )
#end
<td>
${outputName}
</td>
</tr>
</tbody>
</table>
</body>
</html>

 

 is code placement is incorrect? 

Jayant
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Dynamic Content Sorting

It's very surprising to me that you're outputting the entire email from a single Velocity token. That's not usually — well, basically, it's never done.

 

Please reduce the "testing surface" so that you're only outputting the product list (using my debug code) from VTL. Don't mix in anything else, put everything else in the template.

Jayant_Singh
Level 3

Re: Velocity Dynamic Content Sorting

I am using only the debug code and removed everything from VTL.

 

#set( $coList = $pro_cList )
#foreach( $record in $coList )
#foreach( $kv in $record.entrySet() )
{kv.getKey()} ${display.alt($kv.getValue().class,"")} ${display.alt($kv.getValue(),"null")}
#end
#end
${coList}

 

 In the template, I am using {{my.VTL}}  to debug it now. is it ok now or need to add code more?

Jayant
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Dynamic Content Sorting

That's seems like the right start.

 

So what's in the output?

Jayant_Singh
Level 3

Re: Velocity Dynamic Content Sorting

 

{kv.getKey()} class java.lang.String 2020-03-23 08:20:02 {kv.getKey()} class java.lang.String 4 {kv.getKey()} class java.lang.String https://www.mdg.co.in/product/item4.html {kv.getKey()} class java.lang.String b1c1c49a-1545-3c38-a421-d3af748ac5c1 {kv.getKey()} class java.lang.String http://ta-sj29.marketo.com/rs/717-ICG-368/images/item4.png {kv.getKey()} class java.lang.String item3 {kv.getKey()} class java.lang.String 2020-04-24 08:20:02 {kv.getKey()} class java.lang.String 5 {kv.getKey()} class java.lang.String https://www.mdg.co.in/product/item6.html {kv.getKey()} class java.lang.String b1c1c49a-1545-3c38-a421-d3af748ac5c1 {kv.getKey()} class java.lang.String http://ta-sj29.marketo.com/rs/717-ICG-368/images/item6.png {kv.getKey()} class java.lang.String item4 {kv.getKey()} class java.lang.String 2020-05-20 08:20:02 {kv.getKey()} class java.lang.String 6 {kv.getKey()} class java.lang.String https://www.mdg.co.in/product/item5.html {kv.getKey()} class java.lang.String b1c1c49a-1545-3c38-a421-d3af748ac5c1 {kv.getKey()} class java.lang.String http://ta-sj29.marketo.com/rs/717-ICG-368/images/item5.png {kv.getKey()} class java.lang.String item5 [{date=2020-03-23 08:20:02, leadID=4, productCTA=https://www.mdg.co.in/product/item4.html, productID=b1c1c49a-1545-3c38-a421-d3af748ac5c1, productImage=http://ta-sj29.marketo.com/rs/717-ICG-368/images/item4.png, productName=item3}, {date=2020-04-24 08:20:02, leadID=5, productCTA=https://www.mdg.co.in/product/item6.html, productID=b1c1c49a-1545-3c38-a421-d3af748ac5c1, productImage=http://ta-sj29.marketo.com/rs/717-ICG-368/images/item6.png, productName=item4}, {date=2020-05-20 08:20:02, leadID=6, productCTA=https://www.mdg.co.in/product/item5.html, productID=b1c1c49a-1545-3c38-a421-d3af748ac5c1, productImage=http://ta-sj29.marketo.com/rs/717-ICG-368/images/item5.png, productName=item5}]

 

Jayant
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Dynamic Content Sorting

You have a typo.

 

{kv.getKey()} 

is supposed to be

${kv.getKey()} 

 

Also, can you please do this in the Text-only version of the email so the line breaks are preserved? 🙂 Kind of impossible to read otherwise.

Jayant_Singh
Level 3

Re: Velocity Dynamic Content Sorting

date class java.lang.String 2020-03-20 08:20:02
leadID class java.lang.String 1
productCTA class java.lang.String https://www.mdg.co.in/product/item.html
productID class java.lang.String 059130d0-b9a5-4691-9f85-4f94afdadffe
productImage class java.lang.String http://ta-sj29.marketo.com/rs/717-ICG-368/images/item.png
productName class java.lang.String item
date class java.lang.String 2020-04-21 08:20:02
leadID class java.lang.String 2
productCTA class java.lang.String https://www.mdg.co.in/product/item2.html
productID class java.lang.String 059130d0-b9a5-4691-9f85-4f94afdadffe
productImage class java.lang.String http://ta-sj29.marketo.com/rs/717-ICG-368/images/item2.png
productName class java.lang.String item1
date class java.lang.String 2020-05-22 08:20:02
leadID class java.lang.String 3
productCTA class java.lang.String https://www.mdg.co.in/product/item3.html
productID class java.lang.String 059130d0-b9a5-4691-9f85-4f94afdadffe
productImage class java.lang.String http://ta-sj29.marketo.com/rs/717-ICG-368/images/item3.png
productName class java.lang.String item2
[{date=2020-03-20 08:20:02, leadID=1, productCTA=https://www.mdg.co.in/product/item.html, productID=059130d0-b9a5-4691-9f85-4f94afdadffe, productImage=http://ta-sj29.marketo.com/rs/717-ICG-368/images/item.png, productName=item}, {date=2020-04-21 08:20:02, leadID=2, productCTA=https://www.mdg.co.in/product/item2.html, productID=059130d0-b9a5-4691-9f85-4f94afdadffe, productImage=http://ta-sj29.marketo.com/rs/717-ICG-368/images/item2.png, productName=item1}, {date=2020-05-22 08:20:02, leadID=3, productCTA=https://www.mdg.co.in/product/item3.html, productID=059130d0-b9a5-4691-9f85-4f94afdadffe, productImage=http://ta-sj29.marketo.com/rs/717-ICG-368/images/item3.png, productName=item2}]
Jayant
Jayant_Singh
Level 3

Re: Velocity Dynamic Content Sorting

Hi Sanford,

I was wondering  if you have gone through the debug code and please let me know the details.

Jayant