SOLVED

Re: Velocity Token - Account based CO

Go to solution
Travis_Schwartz
Level 4

I've been searching all over the community trying to find a solution for this likely easy issue. I feel I had a similar project previously but I can't find it and I've been searching for too long.
I need to create a velocity script that identifies a payment is coming due. I want to identify what the payment is for (credit card, used car, new car, mortgage, etc.) that information is all under the description (string) field in the Marketo custom object under accounts. I would also need to pull in the corresponding due date (upcomingPaymentDate - Date) field

 

This is what I've done so far and it keeps returning the "no matching list found." message when I use records that it should identify as belonging to this script.

 

#foreach( $list in $account_cList )#if( $list.listID.equals("description") )
#set( $targetList = $list )#break
#end
#end
${display.alt($targetList.description, "no matching list found.")}

 

 

Something else I would need to add would be the date the payment would be due. I would love to do it all in the same script, but if I need to do a separate token, I would appreciate some guidance on how to set that up so that they would be linked to make sure the payment due date that the system was referring to was the same item in the description.

 

The end result, I would need to display something similar to:

 

Account Type: $description

Payment Due Date: $upcomingPaymentDate

 

Thank you for your assistance. 

 

1 ACCEPTED SOLUTION
SanfordWhiteman
Level 10 - Community Moderator

You seem to be throwin' stuff at the wall here:

 

#set( $dueDate = [] )
#foreach( $list in $account_cList )
#if( $account_cList.description.equals("ARROWHEAD VISA") )
#set( $dueDate = $account_cList.upcomingPaymentDate )
#end
#end

 

You're setting $dueDate to an empty List ([]). Then you're looping over $account_cList but never checking the individual items (rather bizarrely named $list) in the list!

 

This wouldn't even make sense in pseudo-code, in other words. Try to read your logic out loud as you look at the code, you're not really implementing anything useful here.

 

It sounds like your intended logic is:

  • loop over the list of accounts
  • find the first account that has its description property equal to "ARROWHEAD VISA"
    • set a variable $dueDate to the upcomingPaymentDate property of that account
    • exit from the loop

There's nothing wrong (and everything right) with writing out your business logic in this plain(ish)-English way. It takes years of coding before you can implement something straight away without sketching it out.

 

For the logic above and your known dataset, the code would be

 

#foreach( $account in $account_cList )
#if( $account.description.equals("ARROWHEAD VISA") )
#set( $dueDate = $account.upcomingPaymentDate )
#break
#end
#end

 

View solution in original post

18 REPLIES 18
SanfordWhiteman
Level 10 - Community Moderator

You have to show more of the raw object data to see why the iterate-and-filter technique isn't working. 

 

Also, can you use the syntax highlighter for your code?

 

syntax_vtl.png

Travis_Schwartz
Level 4

What additional raw object data is needed? Does this refer to all of the possible items that could be under the description tag? 

here is the code in the syntax highlighter:

#foreach( $list in $account_cList )#if( $list.listID.equals("description") )
#set( $targetList = $list )#break
#end
#end
${display.alt($targetList.description, "no matching list found.")}

 

I appreciate the help.

SanfordWhiteman
Level 10 - Community Moderator

There's nothing syntactically wrong with your code.

 

But that doesn't mean the data is there, and there's nothing to prove that it is. Can you prove that the property description is a (non-null) property of the object $targetList?

Travis_Schwartz
Level 4

I think that is the problem. The code I used was based on something I found on the community. How would I ensure that it is looking at the description field other than checking it in the token builder?

Travis_Schwartz
Level 4

It's been a couple days and I'm hoping this will get some action on this page. Tagging @SanfordWhiteman if that will help.

 

If I simplify it, perhaps that would give me the immediate solution that I could then incorporate into the other products. 

 

Let's start with the Visa card. I need to create a campaign that is triggered by someone having a payment due in 10 days for their ARROWHEAD VISA.

 

The products live in the account section of our custom objects.

 

We would need a velocity token to display the due date for the corresponding product.

the name of the product (ARROWHEAD VISA) lives in the $account_cList.description field (string), and the payment due date I need lives in the $account_cList.upcomingPaymentDate field (date).


When I export all of the description values for $account_cList.description, the one I need for this project is  {description=ARROWHEAD VISA}. I can export the payment date field as well, and the one I would use (for this individual) is  {upcomingPaymentDate=2020-04-15}

Based on my digging around, I assume I need to do:

 

#set( $dueDate = [] )
#foreach( $list in $account_cList )
#if( $account_cList.description.equals("ARROWHEAD VISA") )
#set( $dueDate = $account_cList.upcomingPaymentDate )
#end
#end

 

But it is not returning results. I'm obviously going wrong somewhere. any assistance would be greatly appreciated.

Tags (2)
Travis_Schwartz
Level 4

When I check description and the upcomingPaymentDate on a particular record that I know has this product I get:

 

{description=ARROWHEAD VISA, upcomingPaymentDate=2020-04-15},

 

but results are still null or empty when I use my coding.

SanfordWhiteman
Level 10 - Community Moderator

You seem to be throwin' stuff at the wall here:

 

#set( $dueDate = [] )
#foreach( $list in $account_cList )
#if( $account_cList.description.equals("ARROWHEAD VISA") )
#set( $dueDate = $account_cList.upcomingPaymentDate )
#end
#end

 

You're setting $dueDate to an empty List ([]). Then you're looping over $account_cList but never checking the individual items (rather bizarrely named $list) in the list!

 

This wouldn't even make sense in pseudo-code, in other words. Try to read your logic out loud as you look at the code, you're not really implementing anything useful here.

 

It sounds like your intended logic is:

  • loop over the list of accounts
  • find the first account that has its description property equal to "ARROWHEAD VISA"
    • set a variable $dueDate to the upcomingPaymentDate property of that account
    • exit from the loop

There's nothing wrong (and everything right) with writing out your business logic in this plain(ish)-English way. It takes years of coding before you can implement something straight away without sketching it out.

 

For the logic above and your known dataset, the code would be

 

#foreach( $account in $account_cList )
#if( $account.description.equals("ARROWHEAD VISA") )
#set( $dueDate = $account.upcomingPaymentDate )
#break
#end
#end

 

Travis_Schwartz
Level 4

One more thing on this, say a member has multiple cards and different due dates. Is there a way to differentiate between the two in the script? I need the script to be able to identify the desired due date and not display the first one it comes across (if that makes sense).

 

The email is set to trigger when someones due date is 10 days out. is it possible for the code to identify which card this would be related to and display the due date for that card?

 

SanfordWhiteman
Level 10 - Community Moderator

The email is set to trigger when someones due date is 10 days out. is it possible for the code to identify which card this would be related to and display the due date for that card?


I think you're sending from a batch still, not actually a trigger campaign, correct?

 

You can look through the list and find all the items whose date is 10 days ago, yes. Convert to Dates and Calendars, run a little date math.

 

But note that if you have more than 1  that was 10 days ago, they're both going to fit into that window. If the granularity is just a full day then there's no other way to decide among them. This may not be a problem, just pointing it out.

Travis_Schwartz
Level 4

I have it setup to where if they meet the criteria of having the loan type, that it requests the campaign, and the trigger is campaign requested, and in the flow it is wait 10 days till the due date, and send the email. I set this up following a template that was setup prior to my time here so there may be a better was of accomplishing this.

SanfordWhiteman
Level 10 - Community Moderator

I have it setup to where if they meet the criteria of having the loan type, that it requests the campaign, and the trigger is campaign requested, and in the flow it is wait 10 days till the due date, and send the email. I set this up following a template that was setup prior to my time here so there may be a better was of accomplishing this.


That's effectively a batch, then.

 

If you were to actually trigger on the CO being added, and have a Wait step directly in that flow, then you would have the special object $TriggerObject which automatically references the object in the list that caused the trigger to fire.

Travis_Schwartz
Level 4

You're correct. I got caught up in terminology. out company uses "batch" as emails that are not automated, but I have it set up as a batch that goes out daily and is still automated.

Travis_Schwartz
Level 4

Thanks, 

It is definitely a learning curve. I look at other examples, feel I understand what they are trying to accomplish, but sometimes the nuances are a little trick.

That is exactly what I am trying to accomplish.

It is still displaying as blank when I preview it or send a test email using a person who has those values in their account CO.


I have double checked to make sure that both the description and upcomingpaymentdate selections are checked off. Is there anything else that I would need to include to get the value to display?

SanfordWhiteman
Level 10 - Community Moderator

There's no output line in the code, that's finding the value and setting $dueDate.

 

If you want to output $dueDate, then you need a line

 

${dueDate}

 

Travis_Schwartz
Level 4

oh, duh. 

 

yep. it works like a charm. 

 

Is it possible to format the date out of the ISO standard? I read your post https://blog.teknkl.com/velocity-days-and-weeks/ but did not see what I was looking to do.

 

I would love for something to go from: 2020-04-15 to display as April 15, 2020 as that would be a the way most people would write it.  is this doable. or does that require significant code to implement?

 

 

SanfordWhiteman
Level 10 - Community Moderator

I would love for something to go from: 2020-04-15 to display as April 15, 2020 as that would be a the way most people would write it. 


Most American people, maybe. 🙂

 


is this doable. or does that require significant code to implement?


 Not significant code at all but pls open another thread for this topic.

Travis_Schwartz
Level 4

I will do that, one other thing on this thread. 

 

I'm trying to understand what happens when a field type changes. If I were to be doing something similar for other products, but wanted to use a field type that was an integer field type, would the integer have to be converted to a string (I just wanted ? if so, how would that fit in? or does this deserve a new thread as well?? it would still be part of the $account field type.

 

for example, say I want to rather have it look at something based off $account.productType (Integer), what would change in the code (other than substituting what was there already). looking around on other posts I had seen you post this to convert an integer to a string, but not sure how it would fit in:

#set( $anInteger = $convert.toInteger( $aString ) )

 

 

#foreach( $account in $account_cList )
#if( $account.productType.equals("9005") )
#set( $dueDate = $account.upcomingPaymentDate )
#break
#end
#end
${dueDate}

 

 

 

 

SanfordWhiteman
Level 10 - Community Moderator

If I were to be doing something similar for other products, but wanted to use a field type that was an integer field type, would the integer have to be converted to a string?

To compare an Integer with an Integer you don't need any conversion at all.  If $var1 and $var2 are Integers then $var1.equals($var2) works fine.

 

#set( $anInteger = $convert.toInteger( $aString ) )

That's converting a String to an Integer, as the name suggests.  (Or, more precisely, creating a new Integer from a String.)