Help with Velocity Scripting | Community
Skip to main content
ckowalczyk
Level 2
July 24, 2024
Solved

Help with Velocity Scripting

  • July 24, 2024
  • 1 reply
  • 3346 views

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

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

so like this?

 

#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} ${License_Group__cList.get(0).Number_of_Unpaid_Licenses__c} ${License_Group__cList.get(0).Total_Called_In_Last_30_Days__c} #foreach( $License_Group__c in $License_Group__cList ) ## $License_Group__c is set to each object in the list in turn #end

 

or is it like this:

#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 #foreach${License_Group__cList.get(0).Number_of_Paid_Licenses__c} #foreach${License_Group__cList.get(0).Number_of_Unpaid_Licenses__c} #foreach${License_Group__cList.get(0).Total_Called_In_Last_30_Days__c} #foreach( $License_Group__c in $License_Group__cList ) ## $License_Group__c is set to each object in the list in turn #end



Or something like this:

#set($totalCalled = $math.toNumber(#foreach$ $License_Group__c.Total_Called_in_last_30_days__c)) #set($numberOfPaidLicenses = $math.toNumber(#foreach$ $License_Group__c.Number_of_Paid_Licenses__c)) #set($numberOfUnpaidLicenses = $math.toNumber(#foreach$ $License_Group__c.Number_of_Unpaid_Licenses__c)) #set($totalLicenses = $totalCalled - $numberOfPaidLicenses - $numberOfUnpaidLicenses) Total Licenses: $totalLicenses #foreach( $License_Group__c in $License_Group__cList ) ## $License_Group__c is set to each object in the list in turn #end

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

1 reply

SanfordWhiteman
Level 10
July 24, 2024

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
July 25, 2024

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
July 25, 2024

Right here: