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?
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"
Could that be why Marketo isn't pulling the current balance? Again, thanks in advance to you and Sandford.
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!
Hi Darshil,
The "Product" field has the product code data:
Hope this helps.
Lucas
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).
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. ๐
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
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.
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:
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.