Re: Selecting a particular Custom object to display in Velocity Token for emails

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Selecting a particular Custom object to display in Velocity Token for emails

By default, the CO records are sorted in descending order of their created date (not always the same as the updated date, i.e., in case a custom object record gets updated after it gets created, its createdAt and updatedAt would be different). If you want to sort it by updatedDate then you can use the sorter method:

 

#set( $sortedList = $sorter.sort($cCUAccount_List,"updatedAt:desc") )  
##The most recently updated is ${sortedList[0]}

 

You should check out Sandy's article on Sorting objects and lists in Velocity.

 

Also, in your testing, did the custom object record associated with the test record have the productCode field set to one of the values in the interestingProductCodes array?

 

 

LCENTENO
Level 3

Re: Selecting a particular Custom object to display in Velocity Token for emails

Hi Darshil,
I just did and this is very good to know. I will try this later today and let you know. Should I apply this immediately after the following code below, before the two #end lines? See below:

#set( $interestingProductCodes = ["NEW AUTO CE12","SECURED OTHER GOODS CE12","REC VEHICLE OE","SECURED OTHER GOODS OE","PCU USED VEHICLE","PCU USED VEHICLE JR MEETING","PCU NEW VEHICLE","NEW AUTO ALTERN IL","USED AUTO ALTERN IL","USED AUTO ALTERN WI","USED AUTO OE","NEW AUTO OE","MOTORCYCLE CE12","REC VEHICLE CE12"] )

#foreach( $account in $cCUAccount_cList )
#if( $interestingProductCodes.contains($account.productCode) )
${account.getCurrentPayment}
#set( $sortedList = $sorter.sort($cCUAccount_List,"updatedAt:desc") )  
The most recently updated is ${sortedList[0]}
#end
#end


Regarding your question about the testing...there isn't a field called "productCode". There is one called "Product"

LCENTENO_0-1683562992832.png

Could that be why Marketo isn't pulling the current balance? Again, thanks in advance to you and Sandford.

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Selecting a particular Custom object to display in Velocity Token for emails

You should sort the list before the for each loop, and use the sorted list variable instead of the "cCUAccount_cList" in the for each loop. Before that make sure you use the correct field you wish to sort your CO records by based on your use case. 🙂

#set( $interestingProductCodes = ["NEW AUTO CE12","SECURED OTHER GOODS CE12","REC VEHICLE OE","SECURED OTHER GOODS OE","PCU USED VEHICLE","PCU USED VEHICLE JR MEETING","PCU NEW VEHICLE","NEW AUTO ALTERN IL","USED AUTO ALTERN IL","USED AUTO ALTERN WI","USED AUTO OE","NEW AUTO OE","MOTORCYCLE CE12","REC VEHICLE CE12"] )

#set( $sortedList = $sorter.sort($cCUAccount_List,"updatedAt:desc"))  
#foreach( $account in $sortedList)
#if( $interestingProductCodes.contains($account.productCode) )
${account.getCurrentPayment}
#end
#end

Which field in your custom object has the product code data (i.e., the data that you want to compare against the $interestingProductCodes array defined at the top)? We thought it was the productCode, but let us know if it's in some other field, perhaps the Product field. Thank you!

LCENTENO
Level 3

Re: Selecting a particular Custom object to display in Velocity Token for emails

Hi Darshil,
The "Product" field has the product code data:

LCENTENO_0-1683566167149.png

Hope this helps.

Lucas

SanfordWhiteman
Level 10 - Community Moderator

Re: Selecting a particular Custom object to display in Velocity Token for emails

Add this line to the end of your code and show the output from Preview by List, please.

${cCUAccount_List}

 

We can’t work on this anymore without looking at the data (which we should’ve been doing from the start).

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Selecting a particular Custom object to display in Velocity Token for emails

I do think that you should be using the Product field as its content in the snapshot do match with the first product code in the “$interestingProductCodes” array, and the list of product codes was supplied by you initially. However, it’d be helpful if you can share output as requested by Sandy, so we can share the exact code and avoid any confusion. Thanks for understanding. 🙂

LCENTENO
Level 3

Re: Selecting a particular Custom object to display in Velocity Token for emails

Hi Darshil,
Apologies. Per yours and Sandford's feedback see below:

#set( $interestingProductCodes = ["NEW AUTO CE12","SECURED OTHER GOODS CE12","REC VEHICLE OE","SECURED OTHER GOODS OE","PCU USED VEHICLE","PCU USED VEHICLE JR MEETING","PCU NEW VEHICLE","NEW AUTO ALTERN IL","USED AUTO ALTERN IL","USED AUTO ALTERN WI","USED AUTO OE","NEW AUTO OE","MOTORCYCLE CE12","REC VEHICLE CE12"] )

#set( $sortedList = $sorter.sort($cCUAccount_List,"updatedAt:desc"))  
#foreach( $account in $sortedList)
#if( $interestingProductCodes.contains($account.productCode) )
${account.getCurrentPayment}
${cCUAccount_List} 
#end
#end

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Selecting a particular Custom object to display in Velocity Token for emails

1. By “add“ that line I meant after the code you already have. Not inside the loop. That’s just going to create duplicate output.

 

2. I need to see the output. Not the code.

LCENTENO
Level 3

Re: Selecting a particular Custom object to display in Velocity Token for emails

Hi Sandford,

Do you mean placing it here after the second #end in the code?

#set( $interestingProductCodes = ["NEW AUTO CE12","SECURED OTHER GOODS CE12","REC VEHICLE OE","SECURED OTHER GOODS OE","PCU USED VEHICLE","PCU USED VEHICLE JR MEETING","PCU NEW VEHICLE","NEW AUTO ALTERN IL","USED AUTO ALTERN IL","USED AUTO ALTERN WI","USED AUTO OE","NEW AUTO OE","MOTORCYCLE CE12","REC VEHICLE CE12"] )

#foreach( $account in $cCUAccount_cList )
#if( $interestingProductCodes.contains($account.productCode) )
${account.getCurrentPayment}
#end
#end
${cCUAccount_List}

 
The output with the code above applied shows like this in preview by person:

LCENTENO_0-1683575849554.png

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Selecting a particular Custom object to display in Velocity Token for emails

Please use Preview by List and ensure you’ve chosen someone with at least one CO record.


The output you’re showing here is not consistent with what you’ve said so far.

 

If the name of the CO list is

$cCUAccount_cList 

and someone has CO records, you would see all those records in the output.