SOLVED

Display Due Date Custom Token in proper format

Go to solution
SanfordWhiteman
Level 10 - Community Moderator

Re: Display Due Date Custom Token in proper format

The way it shows in the UI isn’t relevant (unless it’s a String type field). What matters is the actual value seen by Velocity.

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

I figured as much. When you mentioned "Do you want to try the "yyyy-MM-dd'T'HH:mm:ss" format?" Do you mean applying it to throughout lines 6-10 in the code. See below:

#set( $ISO8601DateOnly = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateOnlyMonthFirst = "yyyy-MM-dd'T'HH:mm:ss" )
#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" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeTZ = "yyyy-MM-dd'T'HH:mm:ss" )

 

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Display Due Date Custom Token in proper format

Nope, just change the value of the variable you're using in the $convert.parse function, i.e., $ISO8601DateTimeTZ variable. Changing others doesn't matter as you aren't referencing those in your convert to date obj or format functions. Other variables have the respective time formats in case you want to use them (those are included as a part of the boilerplate code so you have all widely used formats in one place). Btw- did it work with this datetime format?

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

Hi Darshil,

I'm just not sure where in the code I need to change the value of the variable. Are you referring to line 12? Also I'm not sure what you're referring to when you say value.

#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:ss" )

#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
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Display Due Date Custom Token in proper format

Yes, I meant to update yyyy-MM-dd'T'HH:mm:ss in #12 (i.e., have it like below)

 

#set( $ISO8601DateTimeTZ = "yyyy-MM-dd'T'HH:mm:ss" )

 

Technically, the format you pass to parseDate() must be a subset of the actual string format, and our original value, i.e., yyyy-MM-dd'T'HH:mm was a subset.

 

What is the unformatted output of the nextDueDate field? Earlier you said it was 2010-05-07T15:41:32-05:00 , and we shared the code to process this input date format which isn't working for you, so could you please confirm the output of your original code (i.e., the one below)?

 

#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

 

Based on this we'll share the code required to format the date to MM-dd-yyyy  format.

 

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

Hi Darshil,

Sorry for the delay.  Regarding your inquiry "What is the unformatted output of the nextDueDate field? Earlier you said it was 2010-05-07T15:41:32-05:00 , and we shared the code to process this input date format which isn't working for you, so could you please confirm the output of your original code (i.e., the one below)?"

#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

The output result is below:

LCENTENO_0-1687271738499.png


Also, I updated line 12 per your instructions and it looks to be having the same issue.

LCENTENO_1-1687272175301.png

 

I appreciate your continued assistance and patience. 🙂

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Display Due Date Custom Token in proper format

Ahaa- you don't have the "T" in the unformatted nextDueDate output, you have a space instead! Could 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( $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,
    $ISO8601DateTimeWithSpace, 
    $defaultLocale, 
    $defaultTimeZone
  )
))
${date.format(
  $ISO8601DateOnlyMonthFirst,
  $nextDueDateFormatted,
  $defaultLocale,
  $defaultTimeZone
)}
#end
#end

 

 

 

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

Hi Darshil, 

When I applied this script 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( $nextDueDateFormatted = $convert.toCalendar(

#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,
    $ISO8601DateTimeWithSpace,
    $defaultLocale,
    $defaultTimeZone
  )
))
${date.format(
  $ISO8601DateOnlyMonthFirst,
  $nextDueDateFormatted,
  $defaultLocale,
  $defaultTimeZone
)}
#end
#end



It showed an error when going to preview mode.

LCENTENO_0-1687276268148.png

 

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Display Due Date Custom Token in proper format

Well, you can't have nested #set statements (see lines 12 and 13 in your code). Could you copy the script in my previous comment and try it?

 

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

Oh my goodness, apologies Darshil. I applied the correct code, and it looks like it worked. 🙂

LCENTENO_0-1687281948865.png

Thanks so much for all you do for the Marketo community.