Marketo displaying multiple dates in Custom Token | Community
Skip to main content
New Participant
August 31, 2023
Solved

Marketo displaying multiple dates in Custom Token

  • August 31, 2023
  • 1 reply
  • 2342 views

Greetings Marketo Community,

We wanted to send an email to customers that open a loan with us letting them know when their first payment is due. When a customer opens an account (regardless of the type of account) it is logged as a CO named HasCCUAccount. I wrote code that pulls the next due date, since this is what we want to inform them of.

However, upon testing the email, I noticed that if a customer has several HasCCUAccount COs with a loan product attached to it and blank "Next Due Date" fields, it automatically applies the actual next due date three times.

 

The code I used to pull the Next Due Date is 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 = ["USED LEND PRO INC","NEW LEND PRO INC","NEW AUTO ALTERN WIS","MOTORCYCLE WIS IND","REC VEHICLE WIS IND","USED AUTO WIS IND","NEW AUTO WIS IND","MOTORCYCLE ILL IND","REC VEHICLE ILL IND","USED AUTO ILL IND","NEW AUTO ILL IND","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


Is there a code that I can apply to ensure that it does not pull loan products with blank "Next Due Date" fields? Thanks in advance for any help that can be provided.

Best,

Lucas


This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Darshil_Shah1

Hi Darshil,

This campaign was setup long before I came aboard. The campaign smart list criteria are below:

 


That's a batch campaign. Trigger campaigns are the ones that have trigger(s) in the smart list (the orange ones with the lightning bolt in front). In your case, if you just want to display the CO record that was created last and has non-empty Next Due Date field, you can consider 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 = ["USED LEND PRO INC","NEW LEND PRO INC","NEW AUTO ALTERN WIS","MOTORCYCLE WIS IND","REC VEHICLE WIS IND","USED AUTO WIS IND","NEW AUTO WIS IND","MOTORCYCLE ILL IND","REC VEHICLE ILL IND","USED AUTO ILL IND","NEW AUTO ILL IND","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"] ) #set( $sortedList = $sorter.sort($cCUAccount_cList ,"createdAt:desc") ) #foreach( $account in $sortedList ) #if( $interestingProduct.contains($account.product) && !$account.nextDueDate.equals("")) #set( $nextDueDateFormatted = $convert.toCalendar( $convert.parseDate( $account.nextDueDate, $ISO8601DateTimeWithSpace, $defaultLocale, $defaultTimeZone ) )) ${date.format( $ISO8601DateOnlyMonthFirst, $nextDueDateFormatted, $defaultLocale, $defaultTimeZone )} #break #end #end

 

This script sorts the CO list in the descending order of the createdAt field, loops through it, finds the first record that has a non-empty value of the Next Due Date field, displays it, and then exits (i.e., exits after displaying the next due date of the CO record that was created last). I think you can also directly display the CO record at the 0th index post sorting, given that the CO record last added would not have the Next Due Date empty. Let us know if you have questions.

1 reply

Darshil_Shah1
Community Manager
August 31, 2023

Are you using a trigger campaign to send email upon CO addition? If so you can use the $TriggerObject to reference correct CO record and its fields instead of looping through the CO list. If it's a batch campaign then you'd need to sort the CO based on the created date, and pick the first CO (at 0th index) and reference its fields. Off the top of my head, there's a small edge case that I'd like to highlight with the batch campaign way: if more than 1 CO records are added to a person record b/w 2 successive batch campaign runs, then the person would only run through this campaign 1x in the next campaign run, and hence would receive the email with the CO record data that added to their record last.

LCENTENOAuthor
New Participant
August 31, 2023

Hi Darshil,

Yes we are using a recurring trigger campaign. Also, I am not sure if this helps but in the HasCCUAccount CO, we have a constraint called "Closed" with True/False selections that indicates if an account is closed. The accounts that are closed are the ones showing a blank "NextDueDate" Field.

Any advice on code that can be used to better apply open accounts with their due dates and not closed accounts? The current code I use is 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 = ["USED LEND PRO INC","NEW LEND PRO INC","NEW AUTO ALTERN WIS","MOTORCYCLE WIS IND","REC VEHICLE WIS IND","USED AUTO WIS IND","NEW AUTO WIS IND","MOTORCYCLE ILL IND","REC VEHICLE ILL IND","USED AUTO ILL IND","NEW AUTO ILL IND","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



Darshil_Shah1
Community Manager
August 31, 2023

I hope you're using the Added to CCUAccount trigger, right? Do you wish to display the NextDueDate of all the open CCUAccount records or just that of the one that triggered the campaign? You can use the $TriggerObject for the latter case to reference the CO record that triggered the campaign. For the former case, you can just add a condition to check whether the CO record has the Closed field set to True before displaying its NextDueDate.