Hi everyone,
Quick question. I have a custom object called "Accounts", which has several different data fed fields including one called "Product". I created the custom tokens in my velocity script (snapshots below) to show the balance, and next date due of a specific product.
Payment Velocity Script:
Next Due Date Velocity Script:
Product Code Velocity Script:
However, the data shown when the tokens are placed in the email is incorrect, as it is pulling the payment amount and due date info for the wrong product. The issue here is that under the "Accounts" custom object, another entry is added for every new product that is purchased by a customer. My question is, is there a string of code that should be applied to the "payment" and or "due date" custom tokens to ensure that the data pulled is for the correct Product? Thanks in advance. 🙂
Best,
Lucas
I have but again, I am a beginner in Velocity and Java so it's a little difficult to wrap my head around it. I have an understanding of the code below, but what I want to know is how do I get the "Current Payment" to display based on the criteria of this code. I do not see anything in the code that references the Current Payment.
#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) )
#end
#end
The display name is CurrentPayment
API Name is currentPayment
Hi @SanfordWhiteman , so I have been playing with the different coding examples you provided and I am still unable to get the token to show the value in the Current Payment field. I have a question, regarding the interesting product code #set you placed (line 1).
#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) )
$lead.Lead_CurrentPayment
#end
#end
How does Marketo recognize this if the field and Custom object is labeled "Product". Does adding this effect the ability to grab the right info? Secondly after the line with the "if" code, is the next line below the correct action line to get the token to display the Current Payment based on the criteria?
Thanks in advance for your continued help.
Best,
Lucas
How does Marketo recognize this if the field and Custom object is labeled "Product".
Sorry, don’t understand the question. You said the Custom Object list is:
$cCUAccount_cList
And you said the Custom Object has property names like:
productName
You’d only know these names if you dragged first dragged the object onto the Script Editor “canvas” (left hand side) from the tree (right hand side).
Hi Sandford,
Basically, every time a member opens a new product account it's housed under the CO category of CCU Account. To answer your question, yes, the CO is named CCU Account with these display names.
I just want to create two separate custom tokens to pull CurrentPayment and NextDueDate display information, based on the "Product" display name categories, since there can be several different CCU Account COs per member, hence the list of 14 products mentioned in previous posts.
Is there a "one-stop-shop' code that can pull this info and be applied to both of the custom tokens for "currentpayment" and "nextduedate"?
Hopefully this makes more sense.
Best,
Lucas
Agreed! To Sandy's point you should be pulling attributes you want to use in the velocity script from the object tree on the right of the email script editor (snapshot below):
Unless the referenced attributes aren't check-marked in the tree, they won't be available to the email script token during the runtime, and Marketo won't be able to reference their value in the code.
I've added a snippet below for your reference as well:
#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.currentpayment}
${account.nextduedate}
#end
#end
This code snippet will display "currentpayment" and "nextduedate" for all the CO records with productCode set to one of the interesting product code values for a person. You may break this email script token into 2 tokens if you wish to display "currentpayment" and "nextduedate" at different places and not together. Additionally, if you only want to print the most recently updated matching record, then you'd have to sort the CO. Let us know if you need help in the code for the sort.
Hi Darshil,
This is starting to make more sense. I checked off the items on the right in the script editor then applied the token code you provided into the email. When I previewed using a specific account that only had one loan, it is still not showing the currentpayment amount.
See screenshot below:
Since this is going to be sent to members who open a new loan. We will definitely want to ensure that Marketo pulls the correct CO record. Any help as far as adjusting the code you provided to pull the most recent loan account only, and addressing the issue above is greatly appreciated. Also, I appreciate the continued support of both yourself and Sandford.
Best,
Lucas
By default, the CO records are sorted in descending order of their created date (not always the same as the updated date, i.e., in case a custom object record gets updated after it gets created, its createdAt and updatedAt would be different). If you want to sort it by updatedDate then you can use the sorter method:
#set( $sortedList = $sorter.sort($cCUAccount_List,"updatedAt:desc") )
##The most recently updated is ${sortedList[0]}
You should check out Sandy's article on Sorting objects and lists in Velocity.
Also, in your testing, did the custom object record associated with the test record have the productCode field set to one of the values in the interestingProductCodes array?
Hi Darshil,
I just did and this is very good to know. I will try this later today and let you know. Should I apply this immediately after the following code below, before the two #end lines? See below:
#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.getCurrentPayment}
#set( $sortedList = $sorter.sort($cCUAccount_List,"updatedAt:desc") )
The most recently updated is ${sortedList[0]}
#end
#end
Regarding your question about the testing...there isn't a field called "productCode". There is one called "Product"
Could that be why Marketo isn't pulling the current balance? Again, thanks in advance to you and Sandford.
You should sort the list before the for each loop, and use the sorted list variable instead of the "cCUAccount_cList" in the for each loop. Before that make sure you use the correct field you wish to sort your CO records by based on your use case. 🙂
#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"] )
#set( $sortedList = $sorter.sort($cCUAccount_List,"updatedAt:desc"))
#foreach( $account in $sortedList)
#if( $interestingProductCodes.contains($account.productCode) )
${account.getCurrentPayment}
#end
#end
Which field in your custom object has the product code data (i.e., the data that you want to compare against the $interestingProductCodes array defined at the top)? We thought it was the productCode, but let us know if it's in some other field, perhaps the Product field. Thank you!
Hi Darshil,
The "Product" field has the product code data:
Hope this helps.
Lucas
I do think that you should be using the Product field as its content in the snapshot do match with the first product code in the “$interestingProductCodes” array, and the list of product codes was supplied by you initially. However, it’d be helpful if you can share output as requested by Sandy, so we can share the exact code and avoid any confusion. Thanks for understanding. 🙂
Hi Darshil,
Apologies. Per yours and Sandford's feedback see below:
#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"] )
#set( $sortedList = $sorter.sort($cCUAccount_List,"updatedAt:desc"))
#foreach( $account in $sortedList)
#if( $interestingProductCodes.contains($account.productCode) )
${account.getCurrentPayment}
${cCUAccount_List}
#end
#end
1. By “add“ that line I meant after the code you already have. Not inside the loop. That’s just going to create duplicate output.
2. I need to see the output. Not the code.
Hi Sandford,
Do you mean placing it here after the second #end in the 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.getCurrentPayment}
#end
#end
${cCUAccount_List}
The output with the code above applied shows like this in preview by person:
Please use Preview by List and ensure you’ve chosen someone with at least one CO record.
The output you’re showing here is not consistent with what you’ve said so far.
If the name of the CO list is
$cCUAccount_cList
and someone has CO records, you would see all those records in the output.
Hi Sandford,
I hope I got this correct. So, I applied this code below:
#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.getCurrentPayment}
#end
#end
#set($currentPayment = $number.currency(${cCUAccount_cList.get(0).currentPayment}))
#if(!$currentPayment)
#set($currentPayment = "$0.00")
#end
${currentPayment}
It looks like it is displaying the payment information when I previewed by a list:
That being said, can you confirm if I am on the right track?
Along with the current payment, we also want to grab the NextDueDate that corresponds with that CO that displays the $850.47.
Is there anything that can be done with the above code to ensure that it grabs the information in the NextDueDate field? Thanks in advance.
Lucas
Sorry, this is not at all correct.
Seems like you still don’t understand what List.get(0) (and its synonym, List[0]) is doing. That’s getting the first item in the list, with the list sorted in what you should consider arbitrary order to start with. Using this method outside of, and in addition to, the loop makes no sense.
The only scenario in which grabbing List.get(0)makes sense is if (a) you are sure of the sort order because you sorted it yourself, and (b) the first item in the list has a specific business meaning, while all the other items do not.
And you still haven’t shown the raw output of the list as requested above.
Hi Sandford,
So, would I need to eliminate the all the code after line 7 altogether (below), or is there an adjustment that can be made to the already current code?
I also noticed that in the scripting there were these two items, that being ContractDate and Created At.
We are trying to determine a more or less "sweet spot" timeframe to pull the correct record. So, would the two items mentioned above be a factor that needs to be applied to the code below. For example, if we wanted to pull a record with a contract date that was within the last 20 days, or a Created At time of the last 20 days. How would we apply that into the code below?
#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.getCurrentPayment}
#end
#end
#set($currentPayment = $number.currency(${cCUAccount_cList.get(0).currentPayment}))
#if(!$currentPayment)
#set($currentPayment = "$0.00")
#end
${currentPayment}
As far as the raw output of the list, I am not sure what you are referring to. Thanks again for your continued support.
Add this line to the end of your code and show the output from Preview by List, please.
${cCUAccount_List}
We can’t work on this anymore without looking at the data (which we should’ve been doing from the start).
You don’t get the Velocity name for an object or property (we’re talking about Velocity names, not REST API names) from the Admin section.
You get it by dragging it onto the Script Editor canvas, also ensuring that it’s checked off on the right-hand-side.
$interestingProductCodes is just a variable name, a mere identifier local to your script for storing the products you want to search for in Account CO records’ productCode field. Additionally, if it helps, when you loop through a CO list of records, in each iteration, a particular CO record is picked and referenced in the loop body at a time (I.e., it processes records in the order they are stored one by one) until either a break statement is encountered in the loop body or it is done iterating through all the records in the CO. Also, is Lead_CurrentPayment a custom field on the person object field and not a custom field on the Account CO?