Velocity - list values from a field in custom object | Community
Skip to main content
New Participant
March 31, 2023
Solved

Velocity - list values from a field in custom object

  • March 31, 2023
  • 1 reply
  • 5108 views

Hello there!

 

I'm new to Velocity and need some help. I'm trying to list all the names of approved applications within the last 12 hours in an email. We have a custom object with approved timestamp and the name of the application. 

 

 

 

#set ($sortedUpdated = $sorter.sort($appRecord_cList,"ApprovalTimestamp:desc")) #foreach($Record in $sortedUpdated) #if (!(!$!Record.ApprovalTimestamp || $Record.ApprovalTimestamp.isEmpty())) #set ($name = "$Record.Name") #end #end $name

 

 

 

I have not gotten far with this, just trying to list the names first before adding the time component to it. Any help is appreciated, thank you!!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Darshil_Shah1

Try the below script! Make sure to update the correct date time format variable in the set $convtdApprovalTimestamp variable piece as per the date time format of the data you've in the field "ApprovalTimestamp". Currently, it's set to $ISO8601DateTime.

 

Also, instead of looping through entire list and checking whether the difference is less than 12 hrs before printing the Record.Name, you can also print data until the loop encounters the first record where the difference becomes > 12 hours; #break could help breaking out of the loop as soon as the difference becomes > 12 hours. This should work as we're sorting the list in descending order as per ApprovalTimestamp field's value".

 

You should also check out Sandy's Velocitips: Switch email content based on day/time blog post to understand how to deal with the date/time-responsive content in general.

 

 

#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")) #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 ${Record.Name} #end #end

 

 

1 reply

Darshil_Shah1
Darshil_Shah1Accepted solution
Community Manager
March 31, 2023

Try the below script! Make sure to update the correct date time format variable in the set $convtdApprovalTimestamp variable piece as per the date time format of the data you've in the field "ApprovalTimestamp". Currently, it's set to $ISO8601DateTime.

 

Also, instead of looping through entire list and checking whether the difference is less than 12 hrs before printing the Record.Name, you can also print data until the loop encounters the first record where the difference becomes > 12 hours; #break could help breaking out of the loop as soon as the difference becomes > 12 hours. This should work as we're sorting the list in descending order as per ApprovalTimestamp field's value".

 

You should also check out Sandy's Velocitips: Switch email content based on day/time blog post to understand how to deal with the date/time-responsive content in general.

 

 

#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")) #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 ${Record.Name} #end #end

 

 

New Participant
March 31, 2023

Thank you so much Darshil for your help! 🙌 I'm still stuck on how to display a bulleted list of 

 

${Record.Name}

 

in the past 12 hours? I saw something in this post but unsure how to apply it to my Velocity script. Would it need to be something like this?

<li>${display.list($allName,", ")}</li> or <li>${appRecord_cList.get(0).Name}</li>
Darshil_Shah1
Community Manager
March 31, 2023

Well, assuming the "Name" is a field on the custom object, the script that I shared above should be able to print Application Names of all records associated with the person having ApprovalTimestamp in the past 12 hours.