SOLVED

Re: Referencing Multiple Custom Objects

Go to solution
kolbenpreble
Level 1

Referencing Multiple Custom Objects

Is it possible to write a velocity script that references multiple custom objects? The idea would be to have a column on each table (CustomerID) that could be used to match rows on each object. 

Example: 

 

#foreach ($emailAddress in $mUOOnboardingTestMUOTable_cList)
#if (
($mUOOnboardingTestTaskrayTask_cList.CustomerID.equals($mUOOnboardingTestMUOTable_cList.CustomerID)) && 
($mUOOnboardingTestTaskrayTask_cList.taskName.toLowerCase().equals("kickoff")) && 
($mUOOnboardingTestTaskrayTask_cList.taskStatus.toLowerCase().equals("complete"))
)
$mUOOnboardingTestTaskrayTask_cList.toastGUID
#else
<p>Complete restaurant basics</p>
#end
#end

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
peter_fedewa1
Level 2

Re: Referencing Multiple Custom Objects

It is possible to reverence multiple custom object in Velocity. You'll want to be careful with how Marketo handles the record limits. It will only return the first 10 records unless you've already changed your limit: https://experienceleague.adobe.com/docs/marketo/using/product-docs/administration/email-setup/change...

 

One of the major issues I am seeing with your code is that you're trying to reference an array/list like a single record with no array index reference. You'll probably need to loop through the array and use the current loop object as your reference.  You're naming each object $emailAddress but that doesn't actually pull the email address necessarily unless your list is just a bunch of email addresses.  

 

This code is likely imperfect but you could do something like:

 

#foreach ($itemA in $objectA)
  #if ($itemA.id.equals($lead.itemID) && $itemA.elementA.equals("foo") )
    #set ($returnStringA = $itemA.elementB)
    #break
  #else
    #set ($returnStringA = "default")
  #end
#end
#foreach ($itemB in $objectB)
 #if ($itemB.id.equals($returnStringA) )
   #set ($returnStringB = $itemB.elementA)
   #break
 #end
#end
$returnStringB

 

 

 It may help to break the problem down to smaller parts and get each one working before putting it all together. Then you can work on code optimizations if they're available.

- Peter

View solution in original post

SanfordWhiteman
Level 10 - Community Moderator

Re: Referencing Multiple Custom Objects


So to break this problem up I wanted to start with working out the code to check if there is a lead with the field "Customer ID" on both objects.

You have to loop over both lists of objects, one inside the other.

 

The reference $objectB.CustomerID in your code would be looking for the property CustomerID on the list $objectB, which will never exist.

View solution in original post

3 REPLIES 3
peter_fedewa1
Level 2

Re: Referencing Multiple Custom Objects

It is possible to reverence multiple custom object in Velocity. You'll want to be careful with how Marketo handles the record limits. It will only return the first 10 records unless you've already changed your limit: https://experienceleague.adobe.com/docs/marketo/using/product-docs/administration/email-setup/change...

 

One of the major issues I am seeing with your code is that you're trying to reference an array/list like a single record with no array index reference. You'll probably need to loop through the array and use the current loop object as your reference.  You're naming each object $emailAddress but that doesn't actually pull the email address necessarily unless your list is just a bunch of email addresses.  

 

This code is likely imperfect but you could do something like:

 

#foreach ($itemA in $objectA)
  #if ($itemA.id.equals($lead.itemID) && $itemA.elementA.equals("foo") )
    #set ($returnStringA = $itemA.elementB)
    #break
  #else
    #set ($returnStringA = "default")
  #end
#end
#foreach ($itemB in $objectB)
 #if ($itemB.id.equals($returnStringA) )
   #set ($returnStringB = $itemB.elementA)
   #break
 #end
#end
$returnStringB

 

 

 It may help to break the problem down to smaller parts and get each one working before putting it all together. Then you can work on code optimizations if they're available.

- Peter
kolbenpreble
Level 1

Re: Referencing Multiple Custom Objects

Thanks for the info, Peter. Good to know it is possible. 

So to break this problem up I wanted to start with working out the code to check if there is a lead with the field "Customer ID" on both objects. Would that look something like this? 

#foreach ($lead in $ObjectA)
## Check if Customer ID from Object A can be found on Object B
#if (($lead.CustomerID.equals($objectB.CustomerID))
## Return this HTML if true
<p>Leads CustomerID is on both Tables</p>
#else
## Return this HTML if not
<p>Leads's CustomerID is not on both tables</p>
#end
#end
SanfordWhiteman
Level 10 - Community Moderator

Re: Referencing Multiple Custom Objects


So to break this problem up I wanted to start with working out the code to check if there is a lead with the field "Customer ID" on both objects.

You have to loop over both lists of objects, one inside the other.

 

The reference $objectB.CustomerID in your code would be looking for the property CustomerID on the list $objectB, which will never exist.