SOLVED

Re: Marketo displaying multiple dates in Custom Token

Go to solution
LCENTENO
Level 3

Marketo displaying multiple dates in Custom Token

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.

LCENTENO_0-1693492123758.png

 

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


1 ACCEPTED SOLUTION

Accepted Solutions
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Marketo displaying multiple dates in Custom Token

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.

View solution in original post

7 REPLIES 7
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Marketo displaying multiple dates in Custom Token

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.

LCENTENO
Level 3

Re: Marketo displaying multiple dates in Custom Token

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.

LCENTENO_0-1693498559877.png

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

Re: Marketo displaying multiple dates in Custom Token

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.

LCENTENO
Level 3

Re: Marketo displaying multiple dates in Custom Token

Hi Darshil,

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

LCENTENO_0-1693500466553.png

 

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Marketo displaying multiple dates in Custom Token

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.

LCENTENO
Level 3

Re: Marketo displaying multiple dates in Custom Token

Hi Darshil, 

It looks like the code adjustment you suggested worked. I pulled the same record that was displaying the due date 3 times, and tada! 

LCENTENO_0-1693504407718.png

Thanks again for your incredible insight.

Lucas

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Marketo displaying multiple dates in Custom Token

Cool, you're welcome! Please be advised of the edge case pertaining to the use of the batch campaign I mentioned in my first comment (i.e., in case more than 1 CO record gets added to the person's record in the timeframe of yesterday, then the email would only have details of the CO record that was added last). Usually, to avoid that users consider using a trigger campaign with an optional wait step with advanced wait properties if they wish to send an email during a specific date/time instead of sending it instantaneously. Let us know if you've questions.