SOLVED

Re: Filtering Custom Object by Date in Velocity

Go to solution
Samantha_Cossum
Level 3

Filtering Custom Object by Date in Velocity

Hi all,

I have a program running that looks at training records for our clients (which we store in COs) and will send an alert to our vendor to delivery something if the date of the training is within 14 days. I have an email script set up to pull the date of the training in to the alert to the vendor and I had originally set it up to sort by training IDs. While that is working for most I am running into the occasionally issue where the date it pulls in is not the upcoming one. I can't filter these by that date field because not every training is currently scheduled. 

My desire is to try and filter by the date being in the next 14 days. I've looked though the community and tried to apply some things but I'm struggling to get anything to work. Below is the script I already have running:

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/Toronto") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#foreach( $event in $sorter.sort($trainingRecord_cList,"trainingID:asc") )
#if( $event.trainingStatus.equalsIgnoreCase("confirmed") )
#set( $latestEventDate = $event.trainingScheduledStartDate)
#set($origDate = $convert.parseDate($latestEventDate,$ISO8601DateOnly,$defaultLocale,$defaultTimeZone))
#set($formattedDate = $date.format('full_date',$origDate,$defaultLocale,$defaultTimeZone))
$formattedDate#break
#end
#end‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

So preferable, this would pull in the start date of the training if it is confirmed and the started date is within 14 days.

Any suggestions or direction would be much appreciated! Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Filtering Custom Object by Date in Velocity

#set( $distanceDays = $date.whenIs($origDate).getDays() )
#if( $distanceDays >= 0 && $distanceDays <= 14 )
## ... event is within the next 14 days, inclusive ...
#end‍‍‍‍

View solution in original post

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: Filtering Custom Object by Date in Velocity

#set( $distanceDays = $date.whenIs($origDate).getDays() )
#if( $distanceDays >= 0 && $distanceDays <= 14 )
## ... event is within the next 14 days, inclusive ...
#end‍‍‍‍
Samantha_Cossum
Level 3

Re: Filtering Custom Object by Date in Velocity

Worked perfectly! Thanks so much Sanford Whiteman