Default Value for Velocity Token
I've been working on script tokens to beef up our member communications so that on our newsletters we can pass in their next event and the type and date for all trainings some is scheduled for (this information is stored in Custom Objects).
We've used scripts like this in the past so I have the basis working but I'm running into an issue for the upcoming trainings token. The goals is to list out all the trainings and what day they are scheduled for, we have that part working, what I'm struggling with is if they are not scheduled for any trainings, they would like to display a message about how the customer should schedule. Here is the currently token without a default message:
#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( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $Calendar = $date.getCalendar() )
#foreach( $event in $training_Record_cList )
#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) )
#set ($trainingType = $event.trainingType)
#set ($trainingTypeSimple = $trainingType.replaceAll("\s*\(.*\)\s*$", ""))
<ul style="margin-bottom: 0px;">
<li style="margin-bottom: 0px;"><span style="font-style: italic;">$!trainingTypeSimple</span> on $!formattedDate</li>
</ul>
#end
#endI originally tried to tried to do an else statement at the end but it ended up loading in when people had trainings and repeating a bunch of times (I'm guessing because of the #foreach). The other idea I had would be to look for them to not have a record where the training status was confirmed but I ran into a road block with that and could not figure out how to get it to work.
Any help would be greatly appreciated!