Hey Darshil,
That worked!! For my own reference, if we're trying to show two different fields, for example, $Record.Title along with $Record.Name, do I have to loop it separately? Or can I add it together?
#set ($result = $names.add($Record.Name || $Record.Title))
Edit: I think I got it to work by doing the other field separately!
#set ($result = $names.add($Record.Name))
#set ($result2 = $title.add($Record.Title))
That’s not valid VTL (it seems like you’re using syntax from standard SQL?).
You can add a complex object (Map) to the list:
#set( $result = $myList.add({ "Name" : $Record.Name, "Title" : $Record.Title}) )
That isn't valid and won't work. You could just create 2 arrays, use 2 add statements, and print them seperately. Since there's just one iterator available in the loop, you wouldn't be able to print them using a single loop. However, while adding elements to the arrays, you can of course use a single loop, no need to use 2 loops there. Just have an additional statement in the loop body to add the $Record.Title value to the $titles array. I like Sandy's idea about using a map too (you could iterate the map using a single loop.) 🙂
Thank you both so much!! 😭 Got it to work with the code below!
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
#set( $sortedUpdated = $sorter.sort($appRecord_cList,"ApprovalTimestamp:desc") )
#set( $names = [])
#foreach( $Record in $sortedUpdated )
#if(!($Record.ApprovalTimestamp.isEmpty()) )
#set( $convtdApprovalTimestamp=$convert.toCalendar(
$convert.parseDate(
$Record.ApprovalTimestamp,
$ISO8601DateTime,
$defaultLocale,
$defaultTimeZone
)
))
#if($date.difference($convtdApprovalTimestamp,$calNow).getHours() > 12)
#break
#end
#set( $result = $myList.add({ "Name" : $Record.Name, "Title" : $Record.Title}) )
#end
#end
#if ($myList.size().equals(1))
<p style="margin: 0 0; mso-line-height-alt: 29px;">A single line for ${myList.get(0).Name} and ${myList.get(0).Title}</p>
#elseif ($myList.size() > 1)
<p style="margin: 0 0; mso-line-height-alt: 29px;">Here are the list of names and title:<br><br></p>
#foreach ($loopVar in $myList)
<li>$loopVar.Name and $loopVar.Title</li>
#end
#end
Really appreciate your guidance and patience, thank you!