Velocity Script, foreach loop, trying to display multiple results.
Hello Community
We are trying to come up with Velocity Script to display field data from an Custom Object when certain criteria are met. I have it working when there is just one qualifying product but when a person has 2 or more qualifying products, the script does not complete and when I preview the email it give a Communication Failure error.
I have studied many of the really helpful Velocity posts / blogs on this board and have tried to follow the solutions - I suspect I have missed something pretty fundamental somewhere.
To explain what the below is trying to acheive...
1. Create a list of products that qualify
2. Look at the smaller list and display results
I appreciate any help given !
## Find qualifying products & create list
#foreach( $Product in $Object1__cList )
#set( $qualifyingProducts = [] )
#if( $Object1.Days_to_Expire__c.equals("30") )
#set( $void = $qualifyingProducts.add($Product) )
#end
#end
## Search list
#foreach( $Product in $qualifyingProducts )
#set($startDate = $convert.parseDate(${Object1.Warranty_Start__c}, "yyyy-MM-dd"))
#set($formattedStartDate = $date.format("dd/MM/yyyy", $startDate))
#set($endDate = $convert.parseDate(${Object1.Warranty_End__c}, "yyyy-MM-dd"))
#set($formattedEndDate = $date.format("dd/MM/yyyy", $endDate))
#set($defaultTimeZone = $date.getTimeZone().getTimeZone("Europe/London") )
#set($defaultLocale = $date.getLocale() )
#set($calNow = $date.getCalendar() )
#set($ret = $calNow.setTimeZone($defaultTimeZone) )
#set($calConst = $field.in($calNow) )
## Display results in a table, if there are multiple results display more than just one.
Your Product Warranty is about to expire...
Product Name: $Object1.Product_Name__c
Warranty End Date: $formattedEndDate
</br>
#end
*******
I need to add (I think) an important point... also included in the results that I am displaying in the table is a link !
I understand this may cause issues... https://blog.teknkl.com/multiple-marketo-tracked-links-in-velocity/
The link is inside a #if / #else line, the link includes a field... e.g. href="xxx.xxx/xxx/xx?pk=${Object1.field}