SOLVED

Re: Help with Velocity Scripting

Go to solution
ckowalczyk
Level 2

Help with Velocity Scripting

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:

 

ckowalczyk_0-1721846042492.png

 

ckowalczyk_1-1721846059503.png

ckowalczyk_2-1721846073135.png

 

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:

ckowalczyk_3-1721846119777.png

Any help appreciated!

Thanks,

Chris

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Velocity Scripting

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.)

View solution in original post

12 REPLIES 12
SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Velocity Scripting

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.

ckowalczyk
Level 2

Re: Help with Velocity Scripting

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? 

SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Velocity Scripting

Right here:

SanfordWhiteman_0-1721930119602.png

 

ckowalczyk
Level 2

Re: Help with Velocity Scripting

Sorry, but I don't see that anywhere within the token area where the script has been added:

ckowalczyk_0-1721934237853.png

What part of Marketo are you in where you see what you mention below?

SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Velocity Scripting

Not in Marketo. Here on the Nation so we can read your code.

ckowalczyk
Level 2

Re: Help with Velocity Scripting

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
SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Velocity Scripting

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?

ckowalczyk
Level 2

Re: Help with Velocity Scripting

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}
SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Velocity Scripting

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