Hi All, I have a script that I just can't get working, I am using it to learn, but any help would be appreciated.
I have a custom Object called car with the following fields:
Make
Model
Year
Vin (Dedupe)
EmailLinkToPerson (Dedupe)
I am trying to write a foreach loop to show me all records that has a car associated with it. this is my code but it keeps returning 0 when there are 35 records.
#set ($count = 0)
#foreach ($item.emailLinkToPerson in $car_cList)
#set ($count = $count + 1)
#end
number of Cars linked to a person: $count
to test this I have added the following token snippet to an email draft (possible to use LP instead? or whats a better why to test scripts)
{{my.Cars_token}}
Solved! Go to Solution.
@mkto101 ,
by default, Marketo only returns the first 10 rows for a given CO for a given person.
To change this, go to Admin | Email, scroll down, and then change this setting:
Cheers
Jo
@mkto101 ,
I've edited your post to make the code more readable. Here is a link to my blog post on how/why to do this: https://nation.marketo.com/t5/product-blogs/posting-code-in-discussions/ba-p/341001
When posting in future, please make sure to format code for readability please.
You can't use the token on an LP. In Marketo, Velocity is only used in Emails.
So, to your code:
#set ($count = 0)
#foreach ($car in $car_cList)
#set( $count = $math.add($count,1) )
#end
number of Cars linked to a person: $count
Marketo inherently understands the link between a person and their custom objects (if you've set things up properly).
Cheers
Jo
Hi Jo,
thank you so much for the pointers and the advice along the way. The total count is still off, this is really a weird issue, so this person has over 35 cars assigned to him, and the loop now only shows 10. I also tried to follow @SanfordWhiteman advice and wrap in a conditional statement and use List.size instead of a loop and this only gives me 10 record for the person. here is the 2 codes I tried:
#set ($count = 0)
#if( $car_cList.size() != 0)
#set( $count = $car_cList.size() )
#end
$count
the above only returns 10 when there are over 100 records
#set ($count = 0)
#foreach ($car in $car_cList)
#set( $count = $math.add($count,1) )
#end
number of Cars linked to a person: $count
The Above code is the one that you suggested, Joe, and this only returns the first 10 records. Is there a hard limit of 10? it seems odd that the loop would break.
I have ensured that all items in the RHS tree are checked off and when I go to the persons -> Custom Object -> Cars I do see all the cars assigned, and there are over 100 records, I also created a smart list for spot-checking and I also see a long list with over 100 records, but the code only returns the first 10 records.
Thanks for all your help!
Jo alluded to this, but why are you looping at all? No need for that, and it wastes resources. List.size()
returns the count of all items.
Now if you want to get a count of list items that match some particular conditions, then you need to update a separate counter after checking #if()
some conditions match.
hey @SanfordWhiteman
that's a solid advice. Thanks for pointing that out. I rather avoid loops where I can, so this is gold! However, I am still not getting an accurate count. I have multiple persons set up with 5,8,9 and 10 cars all of which are showing accurate count, but the persons with 11+ cars are all defaulting to 10 cars rather than showing the actual count. do you know if there is a hard limit of 10 seems bizarre. It wouldn't reflect the count you see under the person -> Custom Object - > Cars.
With one of the Persons it was showing 5 (accurate count), and I kept adding 1 car at the time to the breaking point, which seems to be greater than 10 records per person. Anything you can share in this regard is appreciated.
TVMIA!
@mkto101 ,
by default, Marketo only returns the first 10 rows for a given CO for a given person.
To change this, go to Admin | Email, scroll down, and then change this setting:
Cheers
Jo
you are the man! thank you!