Velocity Script returns the wrong values | Community
Skip to main content
January 2, 2018
Solved

Velocity Script returns the wrong values

  • January 2, 2018
  • 1 reply
  • 3258 views

Hi,

I'm using Velocity Scripting in our Newsletter in 10 different languages. 

To make the tokens more convenient to fill (there are about 200 different values to change each month), I've chosen to use Velocity instead of the normal Dynamic Content.

The template worked fine when I've created and tested it a couple of weeks ago, but now when I want to create the first newsletter to send the URL values are wrong.

The wrong parameters are not in the wrong language and in the right token, but it's in the right language and i'm using it in a different token (article 5 token passes a couple of times for ex).

It's important to add that the email preview by lead works as expected, and all other tokens except the URL ones are ok. The problem occurs in the actual send in the link tokens.

In the script I'm defining variables for each language and another one for the link leader with , so i can track it. I suspect something has changed in the past weeks and the issue lies here.

Anyone have any thoughts on what happened? It worked well a couple of weeks ago.

Example script attached.

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

You'll definitely need to output the fully-formed <a> as part-Velocity, part-static (or part-other-token) links are not supported.

Not sure what you mean by "param no. 5"? Are you using the same variable names in any of your Velocity tokens?  Because that will break link rendering. See this blog post (that example uses only one token but the same rule applies across tokens, since they share a context).

1 reply

SanfordWhiteman
New Participant
January 3, 2018

Three danger zones are apparent here:

  1. You must emit a fully-formed <a> element from Velocity, but you are just including the opening tag.
  2. Nested #defines are not supported (actually, a single #define isn't supported for URLs, but it usually works)
  3. The code is longer than it needs to be, making debugging more difficult.

I shortened and simplified your code and remedied the above problems. Try this:

## Add Article1 URL for the following languages :

#set( $Url = {

  "English" : "URL1",

  "Arabic" : "URL2",

  "Russian" : "URL3",

  "Spanish" : "URL4",

  "Chinese" : "URL5",

  "Japanese" : "URL6",

  "Korean" : "URL7",

  "Vietnamese" : "URL8",

  "India" : "URL9",

  "Ukraine" : "URL10"

})

##--------------------------------------------------------------------------

## Edit the Month and Year in the UTM's (where it says ##EDIT-ME!!##) :

#set( $ArticleUtmCampaign = "utm_campaign=Monthly_NL_January2018_leads" )

#set( $ArticleUtmCampaignIndia = "utm_campaign=Monthly_NL_January2018_India_leads" )

##--------------------------------------------------------------------------

## No Need To Edit Below Here!!!!!!!

##

## Do not edit this param :

#define( $Article1Link )

<a href="http://${ArticleUrl}?utm_source=email&utm_medium=marketo&${ArticleUtmCampaign}"

   style="text-transform: capitalize; text-decoration:none;background:none;color:white;font-family:'Open Sans',Arial, Helvetica, sans-serif;font-size:16px;font-weight:normal;line-height:120%;text-transform:uppercase;margin:0px;"

   target="_blank"

   name="article1">Click to read article</a>

#end

##--------------------------------------------------------------------------

#if ( $lead.Country == "India")

#set( $ArticleUrl = $Url["India"] )

#set( $ArticleUtmCampaign = $ArticleUtmCampaignIndia )

#elseif ( $Url.containsKey($lead.Segmentation_Language_1014) )

#set( $ArticleUrl = $Url[$lead.Segmentation_Language_1014] )

#else

#set( $ArticleUrl = $Url["English"] )

#end

${Article1Link}

January 3, 2018

Hi @Sanford Whiteman,

Thanks so much for your help!

The Newsletter Template contains 5 articles per language, for each a similar token. I've noticed that param no.5 is the one that repeats itself. Maybe it's a step closer to the solution (HTML attached).

1. The <a> tag is not fully formed, because the text is an other personalized token.I've also tried to close the tag for testing but still the problem remains.

3. Thanks for that! it really makes more sense :-)

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
January 4, 2018

You'll definitely need to output the fully-formed <a> as part-Velocity, part-static (or part-other-token) links are not supported.

Not sure what you mean by "param no. 5"? Are you using the same variable names in any of your Velocity tokens?  Because that will break link rendering. See this blog post (that example uses only one token but the same rule applies across tokens, since they share a context).