Howdy and Halp!
I'm hoping to find some help with a velocity script I am editing. I am just trying to hobble this together to meet a deadline. I am not a coder and just barely understand all that is happening in this script...just well enough to get into trouble. See below. 🙂
I have added a number of references to the field 'appointmentType'. The script is now producing an error:
This is the script I have in place:
#foreach ($appointmentItem in $appointment_cList) set( $todayCalObj =
#$date.toCalendar($date.toDate("yyyy-MM-dd HH:mm",$date.get('yyyy-MM-dd
#HH:mm'))) ) set( $nextAppt = $date.toCalendar($date.toDate("yyyy-MM-dd
#HH:mm",${appointmentItem.appointmentDateTime})) ) set( $inFuture = (
#$nextAppt.getTimeInMillis() - $todayCalObj.getTimeInMillis() ) /
#86400000 ) if ( $inFuture > 1 && $inFuture < 2 &&
#($appointmentItem.appointmentStatus != "Reschedule" ||
#$appointmentItem.appointmentStatus != "Cancelled" ||
#$appointmentItem.appointmentType != "Benefit Renewal" ||
#$appointmentItem.appointmentType != "Clean and Check" ||
#$appointmentItem.appointmentType != "Change of Insurance Consult" ||
#$appointmentItem.appointmentType != "Complimentary Screening" ||
#$appointmentItem.appointmentType != "Complimentary Screening/Demo" ||
#$appointmentItem.appointmentType != "Demo Follow Up" ||
#$appointmentItem.appointmentType != "Diagnostic and Warranty" ||
#$appointmentItem.appointmentType != "Diagnostic Eval and Demo 3yrs +" ||
#$appointmentItem.appointmentType != "Diagnostic Eval/HAC(Hearing Test)& Hearing Aid Che" ||
#$appointmentItem.appointmentType != "Diagnostic Evaluation and Hearing Aid Evaluation" ||
#$appointmentItem.appointmentType != "Diagnostic Evaluation(Hearing Test)" ||
#$appointmentItem.appointmentType != "Earmold Fitting" ||
#$appointmentItem.appointmentType != "Earmold Impression" ||
#$appointmentItem.appointmentType != "Empire Plan Follow up" ||
#$appointmentItem.appointmentType != "Final Denial Consult" ||
#$appointmentItem.appointmentType != "Functional Gain Testing" ||
#$appointmentItem.appointmentType != "HA Exchange" ||
#$appointmentItem.appointmentType != "HAC 45 day trial" ||
#$appointmentItem.appointmentType != "HAC+D-Hearing Aid Check & Demo 3 yrs +" ||
#$appointmentItem.appointmentType != "HAC-Hearing Aid Check less than 3 yrs." ||
#$appointmentItem.appointmentType != "HAE-Hearing Aid Evaluation" ||
#$appointmentItem.appointmentType != "HAE/HAF -Hearing Aid Evaluation & Fitting" ||
#$appointmentItem.appointmentType != "HAF--Hearing Aid Fitting" ||
#$appointmentItem.appointmentType != "Hearing Aid Adoption" ||
#$appointmentItem.appointmentType != "Hearing Aid Consult Follow-Up" ||
#$appointmentItem.appointmentType != "Hearing Aid Evaluation" ||
#$appointmentItem.appointmentType != "Home Delivery/Dispense" ||
#$appointmentItem.appointmentType != "Home Visit" ||
#$appointmentItem.appointmentType != "Insurance Benefit Renewal Follow Up." ||
#$appointmentItem.appointmentType != "Insurance consult f/u needs Demo" ||
#$appointmentItem.appointmentType != "Insurance Consult Follow Up/Fitting Upon Authoriza" ||
#$appointmentItem.appointmentType != "Insurance Consult Initial W/WO Diagnostics" ||
#$appointmentItem.appointmentType != "Insurance Final Denial Follow-Up" ||
#$appointmentItem.appointmentType != "Insurance follow up after Dispense" ||
#$appointmentItem.appointmentType != "Insurance Resubmit" ||
#$appointmentItem.appointmentType != "Lost Device" ||
#$appointmentItem.appointmentType != "New Patient Adult CAE" ||
#$appointmentItem.appointmentType != "New Patient Pediatric CAE" ||
#$appointmentItem.appointmentType != "Office Visit/Referral Consult" ||
#$appointmentItem.appointmentType != "Payment" ||
#$appointmentItem.appointmentType != "Replacement Pick up" ||
#$appointmentItem.appointmentType != "Service/Repair" ||
#$appointmentItem.appointmentType != "Tinnitus Evaluation" ||
#$appointmentItem.appointmentType != "Warranty" ||
#$appointmentItem.appointmentType != "Warranty and Demo over 3 years" ||
#$appointmentItem.appointmentType != "Cancelled" ||
#$appointmentItem.appointmentStatus != "Warranty and HAC less than 3 years" ) )
#set( $nextAppointment =
#$convert.parseDate(${appointmentItem.appointmentDateTime},
#'yyyy-MM-dd HH:mm') )
<p>$date.format('MM/dd/yyyy',$nextAppointment) at $date.format('hh:mm
a',$nextAppointment)<br /> <br>
#break else end
#end
The objective is to exclude the above appointment types and statuses from the email send. I am hoping this just a simple syntax error. Thanks to anyone that is able to have a gander.
Solved! Go to Solution.
There was no solution offered by Marketo for incorrect times showing in emails, so we improvised. Your solution certainly sounds like a much more clean way of doing things.
How bizarre. I wrote a much-visited post on dates & datetimes in Velocity, showing how to include timezones for input and output.
In any case, incorporating the additional assumption that your converted-to-CST datetimes are in fact Strings with the format "yyyy-MM-ddHH:mm" (ex. "2021-01-0712:34") as suggested somewhere above... it sounds like you want this, or something much like it:
#set( $defaultTimeZone = $date.getTimeZone() )
#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.SSSZ" )
## your corporate datetime formats for both input (parsing) and output
#set( $audigyDateTimeInputFormat = "yyyy-MM-ddHH:mm" )
#set( $audigyDateTimeOutputFormat = "MM/dd/yyyy' at 'hh:mma" )
#set( $excludableAppointmentStatuses = ["Reschedule","Cancelled","Rescheduled" ] )
#set( $excludableAppointmentTypes = ["Benefit Renewal","Clean and Check","Change of Insurance Consult","Complimentary Screening","Complimentary Screening/Demo","Demo Follow Up","Diagnostic and Warranty","Diagnostic Eval and Demo 3yrs +","Diagnostic Eval/HAC(Hearing Test)& Hearing Aid Check","Diagnostic Evaluation and Hearing Aid Evaluation","Diagnostic Evaluation(Hearing Test)","Earmold Fitting","Earmold Impression","Empire Plan Follow up","Final Denial Consult","Functional Gain Testing","HA Exchange","HAC 45 day trial","HAC+D-Hearing Aid Check & Demo 3 yrs +","HAC-Hearing Aid Check less than 3 yrs.","HAE-Hearing Aid Evaluation","HAE/HAF -Hearing Aid Evaluation & Fitting","HAF--Hearing Aid Fitting","Hearing Aid Adoption","Hearing Aid Consult Follow-Up","Hearing Aid Evaluation","Home Delivery/Dispense","Home Visit","Insurance Benefit Renewal Follow Up.","Insurance change follow up","Insurance consult f/u needs Demo","Insurance Consult Follow Up/Fitting Upon Authorization","Insurance Consult Initial W/WO Diagnostics","Insurance Final Denial Follow-Up","Insurance follow up after Dispense","Insurance Resubmit","Lost Device","New Patient Adult CAE","New Patient Pediatric CAE","Office Visit/Referral Consult","Payment","Replacement Pick up","Service/Repair","Tinnitus Evaluation","Warranty","Warranty and Demo over 3 years","Warranty and HAC less than 3 years"] )
#foreach( $appointment in $sorter.sort($appointment_cList,"appointmentDateTime:asc") )
#set( $dtAppointment = $convert.parseDate($appointment.appointmentDateTime, $audigyDateTimeInputFormat, $defaultLocale, $defaultTimeZone) )
#set( $calAppointment = $convert.toCalendar($dtAppointment) )
#set( $hoursInFuture = $date.difference($calNow,$calAppointment).getHours() )
#set( $isExcludedStatus = $excludableAppointmentStatuses.contains($appointment.appointmentStatus) )
#set( $isExcludedType = $excludableAppointmentTypes.contains($appointment.appointmentType) )
#if(
$hoursInFuture >= 24 &&
$hoursInFuture <= 48 &&
!$isExcludedStatus &&
!$isExcludedType
)
#set( $nextQualifiedAppointment = $dtAppointment )
#break
#end
#end
<p>$date.format($audigyDateTimeOutputFormat,$nextQualifiedAppointment)<br><br>