You should reference the loop variable $account, and not the $cCUAccount_cList.get(0) while displaying the nextDueDate field. Also, ensure that the nextDueDate custom object field is ticked in the object tree. I recommended pulling the field from the object tree to ensure that you have the correct velocity field name (in your case, nextDueDate) in the script.
Hi Darshil,
Looks like your suggestion worked.
#set( $interestingProduct = ["NEW AUTO CE12","SECURED OTHER GOODS CE12","REC VEHICLE OE","SECURED OTHER GOODS OE","PCU USED VEHICLE","PCU USED VEHICLE JR MEETING","PCU NEW VEHICLE","NEW AUTO ALTERN IL","USED AUTO ALTERN IL","USED AUTO ALTERN WI","USED AUTO OE","NEW AUTO OE","MOTORCYCLE CE12","REC VEHICLE CE12"] )
#foreach( $account in $cCUAccount_cList )
#if( $interestingProduct.contains($account.product) )
${account.nextDueDate}
#end
#end
One last thing, the date and time displays differently due to the Next Due Date field being in a Date format, which Marketo displays by default as 2010-05-07T15:41:32-05:00. However, I was playing with the code below and I am thinking this is right to display it as mm-dd-yyyy (I hope).
$date.format('MMM dd, yyyy hh:mm a', ${convert.parseDate(${lead.nextDueDate}, 'MM-dd-yyyy')}
First and foremost, is this right? Second, would I simply place this after line 4 in the full code above?
You should include the date-time boilerplate in your code. Could you try the below script and let us know if it works?
#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( $ISO8601DateOnlyMonthFirst = "MM-dd-yyyy" )
#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( $interestingProduct = ["NEW AUTO CE12","SECURED OTHER GOODS CE12","REC VEHICLE OE","SECURED OTHER GOODS OE","PCU USED VEHICLE","PCU USED VEHICLE JR MEETING","PCU NEW VEHICLE","NEW AUTO ALTERN IL","USED AUTO ALTERN IL","USED AUTO ALTERN WI","USED AUTO OE","NEW AUTO OE","MOTORCYCLE CE12","REC VEHICLE CE12"] )
#foreach( $account in $cCUAccount_cList )
#if( $interestingProduct.contains($account.product) )
#set( $nextDueDateFormatted = $convert.toCalendar(
$convert.parseDate(
$account.nextDueDate,
$ISO8601DateTime,
$defaultLocale,
$defaultTimeZone
)
))
${date.format(
$ISO8601DateOnlyMonthFirst,
$nextDueDateFormatted,
$defaultLocale,
$defaultTimeZone
)}
#end
#end
This is a great place to learn about using date time in velocity.
Hi Darshil,
I applied the code and this was the result:
Yeah- this has to do with the input format. Basically, the input time format isn't matching the time format we have in the $convert.parseDate function. Can you try the below script?
#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( $ISO8601DateOnlyMonthFirst = "MM-dd-yyyy" )
#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( $ISO8601DateTimeTZ = "yyyy-MM-dd'T'HH:mm" )
#set( $nextDueDateFormatted = $convert.toCalendar(
$convert.parseDate(
$account.nextDueDate,
$ISO8601DateTimeTZ,
$defaultLocale,
$defaultTimeZone
)
))
${date.format(
$ISO8601DateOnlyMonthFirst,
$nextDueDateFormatted,
$defaultLocale,
$defaultTimeZone
)}
Hi Darshil,
I applied the code below:
#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( $ISO8601DateOnlyMonthFirst = "MM-dd-yyyy" )
#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( $interestingProduct = ["NEW AUTO CE12","SECURED OTHER GOODS CE12","REC VEHICLE OE","SECURED OTHER GOODS OE","PCU USED VEHICLE","PCU USED VEHICLE JR MEETING","PCU NEW VEHICLE","NEW AUTO ALTERN IL","USED AUTO ALTERN IL","USED AUTO ALTERN WI","USED AUTO OE","NEW AUTO OE","MOTORCYCLE CE12","REC VEHICLE CE12"] )
#foreach( $account in $cCUAccount_cList )
#if( $interestingProduct.contains($account.product) )
#set( $nextDueDateFormatted = $convert.toCalendar(
$convert.parseDate(
$lead.FirstName,
$ISO8601DateTimeTZ,
$defaultLocale,
$defaultTimeZone
)
))
${date.format(
$ISO8601DateOnlyMonthFirst,
$nextDueDateFormatted,
$defaultLocale,
$defaultTimeZone
)}
#end
#end
The result looks to be the same.
You haven't defined the $ISO8601DateTimeTZ variable before using it in the $convert.parse function. Also, please use the $account.nextDueDate as the input date field. Could you please try the below script:
#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( $ISO8601DateOnlyMonthFirst = "MM-dd-yyyy" )
#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( $ISO8601DateTimeTZ = "yyyy-MM-dd'T'HH:mm" )
#set( $nextDueDateFormatted = $convert.toCalendar(
$convert.parseDate(
$account.nextDueDate,
$ISO8601DateTimeTZ,
$defaultLocale,
$defaultTimeZone
)
))
${date.format(
$ISO8601DateOnlyMonthFirst,
$nextDueDateFormatted,
$defaultLocale,
$defaultTimeZone
)}
Hi Darshil,
I placed the code in
#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( $ISO8601DateOnlyMonthFirst = "MM-dd-yyyy" )
#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( $ISO8601DateTimeTZ = "yyyy-MM-dd'T'HH:mm" )
#set( $interestingProduct = ["NEW AUTO CE12","SECURED OTHER GOODS CE12","REC VEHICLE OE","SECURED OTHER GOODS OE","PCU USED VEHICLE","PCU USED VEHICLE JR MEETING","PCU NEW VEHICLE","NEW AUTO ALTERN IL","USED AUTO ALTERN IL","USED AUTO ALTERN WI","USED AUTO OE","NEW AUTO OE","MOTORCYCLE CE12","REC VEHICLE CE12"] )
#foreach( $account in $cCUAccount_cList )
#if( $interestingProduct.contains($account.product) )
#set( $nextDueDateFormatted = $convert.toCalendar(
$convert.parseDate(
$account.nextDueDate,
$ISO8601DateTimeTZ,
$defaultLocale,
$defaultTimeZone
)
))
${date.format(
$ISO8601DateOnlyMonthFirst,
$nextDueDateFormatted,
$defaultLocale,
$defaultTimeZone
)}
#end
#end
It still looks to be the same result:
Well, the format "yyyy-MM-dd'T'HH:mm" works for me when I tested it with the input "2010-05-07T15:41:32-05:00" (see the snapshot below). Additionally, see this very similar post where the user also wanted to parse the exact datetime format. Do you want to try the "yyyy-MM-dd'T'HH:mm:ss" format?
Hi Darshil,
Not sure if this is a factor, but I looked at how our member next due date fields are displayed and this is how it shows in the field:
Do you think this may have a factor in why the code isn't working?