SOLVED

Display Due Date Custom Token in proper format

Go to solution
LCENTENO
Level 3

Display Due Date Custom Token in proper format

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

Accepted Solutions
Darshil_Shah1
Level 10 - Community Advisor

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

 

 

 

View solution in original post

30 REPLIES 30
SanfordWhiteman
Level 10 - Community Moderator

Re: Display Due Date Custom Token in proper format


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

Hmm, how is it “based on” their product code? Do you mean “if their product code is in the list of interesting codes”? Always best to be explicit.

 

Is getNextDueDate the Velocity name of the field whose friendly name is NextDueDate? How have you determined that Velocity name? More important what does the whole $cCUAccount_cList list look like when you output it (this is an absolutely key part of troubleshooting)?

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

Hi @SanfordWhiteman , yes I am referring to if their product code is in the interesting codes list that I provided. Yes, NextDueDate is the field name within the CCUAccount CO.  

As far as your last question "More important what does the whole $cCUAccount_cList list look like when you output it (this is an absolutely key part of troubleshooting)?" I am not sure what you are asking.

Darshil_Shah1
Level 10 - Community Advisor

Re: Display Due Date Custom Token in proper format

What output do you get when you just add ${cCUAccount_cList} in your email script token? This will display the list of all the custom object records associated with that person record.

 

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

Hi Darshill,

Do you mean adding it to the code I already displayed previously?

#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


If so, would I add it after the ${account.getNextDueDate} line?

Darshil_Shah1
Level 10 - Community Advisor

Re: Display Due Date Custom Token in proper format

You can add a line to display the list with the existing script token content but to get away from clutter, just have a script token with ${cCUAccount_cList}, and show us the output of it (of course, after masking sensitive info) for one of the person records you don't seem to get the correct results for your original script (as you've mentioned in your original question).

 

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

Hi Darshil, 

The output that shows with the ${cCUAccount_cList} script token is below (used zeroes to mask sensitive info displayed):

[{product=VISA Signature Cash Rebate, nextDueDate=null}, {product=NEW AUTO CE12, nextDueDate=0000-00-00 00:00:00}, {product=Membership Savings, nextDueDate=null}, {product=Rewards Checking, nextDueDate=null}, {product=Rewards Checking, nextDueDate=null}, {product=Rewards Checking, nextDueDate=null}, {product=Holiday Club Savings, nextDueDate=null}, {product=Membership Savings, nextDueDate=null}, {product=Membership Savings, nextDueDate=null}, {product=USED AUTO CE 12, nextDueDate=null}]

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Display Due Date Custom Token in proper format

You’re using the wrong field names (not sure where you’re getting those other names?).


It’s product, not productCode.

 

It’s nextDueDate, not getNextDueDate.

Darshil_Shah1
Level 10 - Community Advisor

Re: Display Due Date Custom Token in proper format

Agreed with Sandy! For reference, pull the field into the editor from the object tree on the right (snapshot below) to get the correct field name instead of typing it out. I hope this helps.

Darshil_Shah1_0-1686768473031.png

 

LCENTENO
Level 3

Re: Display Due Date Custom Token in proper format

Hey Darshill,

I think I am on the right track here. I applied your advice along with Sandford's advice about naming the fields correctly. The code I placed is 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) )
${cCUAccount_cList.get(0).nextDueDate}
#end
#end

For line 4, I pulled the NextDueDate field from the object tree on the right as you instructed. When I place the token in the email this is what displayed in preview mode.

LCENTENO_0-1686842375658.png

Is there a reason why it's displaying the name of the field pulled in and not the actual due date?