SOLVED

Display Due Date Custom Token in proper format

Go to solution
LCENTENO
Level 3

Greetings Community,

I feel like I am circling around the airport on this one, and I would love to bring this baby in for a landing.

Part 1:

We want to let our members know when their next payment is due. I have checked off the Product and NextDueDate checkboxes in the CCUAccount Custom object.

LCENTENO_0-1686598996115.png


I put this code below into Velocity script which is supposed to show the Next Due Date based on their product code:

#set( $interestingProductCodes = ["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( $interestingProductCodes.contains($account.productCode) )
${account.getNextDueDate}
#end
#end

However, when I test the token in an email using contacts, nothing shows up. Is there any code I am missing here?

Part Two: The "NextDueDate" a date and time field displays the due date in this format: YYYY-MM-DDThh:mm:ssTZD. What code can I apply to the above to change it to show the date as MM-DD-YYYY? 

Thanks so much in advance.


1 ACCEPTED SOLUTION
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

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

 

 

 

View solution in original post

30 REPLIES 30