Hi,
I've been trying to build out one Velocity Script Token that has a fairly simple equation:
License_Group.Total_Called_in_last_30_days - License_Group.Number_of_Paid_Licenses - License_Group.Number_of_Unpaid_Licenses
Here are the screenshots of how it looks when it's in script:
But when I reference the token in the email, it seems to always come out like this and will not populate when using a test record I know should populate it:
Any help appreciated!
Thanks,
Chris
Solved! Go to Solution.
None of those. You only work with $License_Group__c
inside the loop, otherwise it does not exist in the Velocity context and will be null
.
So closest to the 3rd one, but any reference to $License_Group__c
inside the #foreach
.
(Honestly not even sure where you’d get the idea $License_Group__c
could be used. That’s not a variable Marketo declares for you. Only the list is declared.)
Please use the Syntax Highlighter (“Insert/Edit Code Sample” on the button bar) to insert code so it’s readable. It’s not possible to work with a screenshot.
Hi Sanford - sorry but I don't follow. The velocity code is in a token. I don't see a “Insert/Edit Code Sample” on the button bar. How/where would I accomplish this?
Right here:
Sorry, but I don't see that anywhere within the token area where the script has been added:
What part of Marketo are you in where you see what you mention below?
Not in Marketo. Here on the Nation so we can read your code.
Ahh ok cool, thank you! Here you go:
#set($totalCalled = $math.toNumber($License_Group__c.Total_Called_in_last_30_days__c))
#set($numberOfPaidLicenses = $math.toNumber($License_Group__c.Number_of_Paid_Licenses__c))
#set($numberOfUnpaidLicenses = $math.toNumber($License_Group__c.Number_of_Unpaid_Licenses__c))
#set($totalLicenses = $totalCalled - $numberOfPaidLicenses - $numberOfUnpaidLicenses)
Total Licenses: $totalLicenses
Something doesn’t add up here. $License_Group__c
should be a list of objects, not an individual object. Create a new Email Script {{my.token}}. What do you see when you drag the field Number of Paid Licenses (SE) to the Script Editor canvas?
This is what I see when I drag it over:
#set($totalCalled = $math.toNumber($License_Group__c.Total_Called_in_last_30_days__c))
#set($numberOfPaidLicenses = $math.toNumber($License_Group__c.Number_of_Paid_Licenses__c))
#set($numberOfUnpaidLicenses = $math.toNumber($License_Group__c.Number_of_Unpaid_Licenses__c))
#set($totalLicenses = $totalCalled - $numberOfPaidLicenses - $numberOfUnpaidLicenses)
Total Licenses: $totalLicenses$
${License_Group__cList.get(0).Number_of_Paid_Licenses__c}
That’s in line with what I was saying. You have a list of objects: $License_Group__cList
. You have to loop (#foreach
) over that list. You don’t have an object $License_Group__c
unless you happen to use that as the loop variable.
#foreach( $License_Group__c in $License_Group__cList )
## $License_Group__c is set to each object in the list in turn
#end