Token prints out velocity variable instead of link | Adobe Higher Education
Skip to main content
Joe_Fusaro
Level 2
January 7, 2019
Beantwoord

Token prints out velocity variable instead of link

  • January 7, 2019
  • 2 reacties
  • 3452 Bekeken

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?

Er kunnen geen reacties meer worden geplaatst op dit onderwerp.
Beste antwoord door SanfordWhiteman

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:

  • $Provisioning__cList is not present in the Velocity context (i.e. not checked off in the tree, or you're using a sample)
  • $Provisioning__cList exists but is not a List, so has no get method
  • $Provisioning__cList is a List with an object at index 0, but that object doesn't have a License_Code__c property
  • $Provisioning__cList is a List with an object at index 0, and that object has a License_Code__c property, but the property is an empty String

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?

2 reacties

Level 6
January 7, 2019

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

Joe_Fusaro
Level 2
January 8, 2019

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..." ?

SanfordWhiteman
Level 10
January 8, 2019

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.

SanfordWhiteman
Level 10
January 8, 2019

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:

  • $Provisioning__cList is not present in the Velocity context (i.e. not checked off in the tree, or you're using a sample)
  • $Provisioning__cList exists but is not a List, so has no get method
  • $Provisioning__cList is a List with an object at index 0, but that object doesn't have a License_Code__c property
  • $Provisioning__cList is a List with an object at index 0, and that object has a License_Code__c property, but the property is an empty String

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?