I created a program token, activation_link, that should pull a link from a custom Salesforce object that is synced with Marketo. The velocity script is:
#if(${Provisioning__cList.get(0).License_Code__c}=="")
#set($HTMLSafeString = "Please email support for your activation code" )
#else
#set($HTMLSafeString = $esc.html(${Provisioning__cList.get(0).License_Code__c}))
#end
${HTMLSafeString}
In my email body, I put the token {{my.activation_link}} but this prints out
${HTMLSafeString}
instead of the link, as expected. I think the value exists because it's getting to the 'else' part of the script, but it's just not rendering as expected.
What am I doing wrong?
Solved! Go to Solution.
Joe, make sure you're testing using only Preview-by-List or with a real Send Email -- not Send Sample. The entire lead isn't loaded with a sample, so you can't test Velocity that way.
Like Mark says, don't use ${formal} notation inside a #set, as that makes it easier to make syntax errors. Use $simple notation unless you're outputting text.
I think the value exists because it's getting to the 'else' part of the script, but it's just not rendering as expected.
Not necessarily!
Because of the way Velocity handles/swallows exceptions, your first condition will be false in any of the following circumstances:
As you can see there are several code paths by which you could end up in the #else condition but not be working with the object you expect.
When are we getting that beer anyway?
Joe, make sure you're testing using only Preview-by-List or with a real Send Email -- not Send Sample. The entire lead isn't loaded with a sample, so you can't test Velocity that way.
Like Mark says, don't use ${formal} notation inside a #set, as that makes it easier to make syntax errors. Use $simple notation unless you're outputting text.
I think the value exists because it's getting to the 'else' part of the script, but it's just not rendering as expected.
Not necessarily!
Because of the way Velocity handles/swallows exceptions, your first condition will be false in any of the following circumstances:
As you can see there are several code paths by which you could end up in the #else condition but not be working with the object you expect.
When are we getting that beer anyway?
I would try:
- removing the formal notation aside from output
- double check that the custom object field is selected in the field tree where you input the script
Hi Mark, What do you mean the "formal notation" ?
Are you suggesting to just include the following in the velocity script?
${Provisioning__cList.get(0).License_Code__c}
This is directly to the left of the field that I'm referencing, License Code (License_Code__c):
Is this what you meant with "double check that the custom object field is selected..." ?
Hi Mark, What do you mean the "formal notation" ?
Formal is with the extra curly braces.
Simple is
$esc.html($Provisioning__cList.get(0).License_Code__c)
The reason simple is recommended is this is a syntax error
$esc.html(${Provisioning__cList.get(0).License_Code__c}.toString())
but this is not
$esc.html($Provisioning__cList.get(0).License_Code__c.toString())
So the formal notation is (obviously) not an error used totally on its own, but if you try to chain additional methods you'll get an error.