SOLVED

Display Due Date Custom Token in proper format

Go to solution
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Display Due Date Custom Token in proper format

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.

 

 

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

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?

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Display Due Date Custom Token in proper format

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.

 

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

Hi Darshil,

I applied the code and this was the result:

LCENTENO_0-1686935668216.png

 

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Display Due Date Custom Token in proper format

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
)}

 

 

 

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

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.

LCENTENO_0-1686939207873.png

 



Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Display Due Date Custom Token in proper format

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
)}

 

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

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:

LCENTENO_0-1686941382170.png

 





Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Display Due Date Custom Token in proper format

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?

 

Darshil_Shah1_0-1686943724601.png

 

Darshil_Shah1_1-1686943762408.png

 

 

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper 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:

LCENTENO_0-1686946166729.png


Do you think this may have a factor in why the code isn't working?