AnsweredAssumed Answered

Pull Custom Object Record by Most recent Date in Field

Question asked by Samantha Cossum on May 8, 2019
Latest reply on May 9, 2019 by Samantha Cossum

Hi all,

We store our customer's training history in a custom object. We use the velocity scripts to pull in the date of upcoming trainings and I am trying to take that script and adjust it to pull the last day they had a specific training but having issues getting it to pull the most recent date. 


I've read a bunch of articles on here and and around the web but I'm still struggling to get it to work/apply to our specific situation. Our code is a little messy because we pull off the training types (which have changed over the years) and for this specific use case, that the status of training is complete (due to a change in our sync the case changed so I'm accounting for that as well). The actually date I want to pull in is the most recent end date of the training. Below is my code.Everything I tried to add to make it work just broke the script so this is without any of tries at sorting. 


#set($startDate = $trainingRecord_cList)
#set($type = $trainingRecord_cList)
#foreach($event in $startDate)
#if(($event.trainingType == "New Patient Mastery On-Site Solution (New Member)" || $event.trainingType == "New Patient Mastery (New Member)" || $event.trainingType == "5 Star Telephone Training (New Member)" || $event.trainingType == "5 Star Telephone Training (New Member))" || $event.trainingType == "5 Star Telephone Training (Upgrade)" || $event.trainingType == "Advanced Telephone & Capacity Techniques" || $event.trainingType == "New Patient Mastery (Upgrade)" || $event.trainingType == "New Patient Mastery On-Site Solution (Upgrade)") && ($event.trainingStatus == "complete" || $event.trainingStatus == "Complete"))
#set($origDate = $convert.parseDate($event.trainingScheduledEndDate,"yyyy-MM-dd"))
#set($formattedDate = $date.format('full_date',$origDate))


I'm still newer to Velocity and the scripts we use for our trainings were built beside an outside company before I came on so any suggestions would be very much appreciated!