Hi There! I would like to ask for some help regarding a script we are currently working on. This script works however there are some cases in which the order date is the same with other product category which result to error. The error occur for this example, I have data with Stickers and Postcards order at the same time but I just need to show the data for postcards which is in second list.
Sample data:
Itemlist 1 - Stickers - Order date: Oct 9, 2020
Itemlist 2 - Postcards - Order date: Oct 9, 2020
Itemlist 3 - Postcards - Order date: Sept 4, 2020
My question would be, how can I retrieve a data in Itemlist 2 using the lastindex value since I need to still get the recent purchase for a specific product.
#set($product = "Postcards")
#set($size = $jobItemList.size())
#set($lastIndex = $jobItemList.size() - 1)
#set($joID = ${jobItemList.get($lastIndex).jobOrderId})
#foreach( $item in $jobItemList )
#if ($item.productCategory == $product && $item.jobOrderId == $joID)
$item.jobOrderId
#break
#end
#end
Solved! Go to Solution.
What I am trying to do is to get the recent order in the jobItemlist which equals to the product value I declare -> #set($product = "Postcards"). Does I make sense?
Yes, and that's much easier than what your code is doing now! You must've gotten mixed up somewhere along the way.
You don't need to be seeking an index or anything like that. Just sort the list, match the interesting product, and break after you found it.
#set( $targetProduct = "Postcards" )
#if( !$jobItemList.isEmpty() )
#foreach( $jobItem in $sorter.sort($jobItemList,"orderDate:desc") )
#if( $jobItem.productCategory.equals($targetProduct) )
${jobItem.jobOrderId}
#break
#end
#end
#end
(Obvs. substitute the field name for Order Date where I have orderDate — I don't know what its name is in your particular instance.)
Please provide more of a business-level description of what you're trying to do. The code is not giving a complete picture. You're trying to traverse the list to find the last item ("last" when sorted on what property?) and then find the first item that has that last item's jobOrderID?
Thanks for that quick response Sandford.
What I am trying to do is to get the recent order in the jobItemlist which equals to the product value I declare -> #set($product = "Postcards").
Does I make sense?
What I am trying to do is to get the recent order in the jobItemlist which equals to the product value I declare -> #set($product = "Postcards"). Does I make sense?
Yes, and that's much easier than what your code is doing now! You must've gotten mixed up somewhere along the way.
You don't need to be seeking an index or anything like that. Just sort the list, match the interesting product, and break after you found it.
#set( $targetProduct = "Postcards" )
#if( !$jobItemList.isEmpty() )
#foreach( $jobItem in $sorter.sort($jobItemList,"orderDate:desc") )
#if( $jobItem.productCategory.equals($targetProduct) )
${jobItem.jobOrderId}
#break
#end
#end
#end
(Obvs. substitute the field name for Order Date where I have orderDate — I don't know what its name is in your particular instance.)
Thanks a lot Sandford. Will give this a try 🙂