SOLVED

Re: Velocity Script returns the wrong values

Go to solution
Anonymous
Not applicable

Velocity Script returns the wrong values

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 http://, 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.

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script returns the wrong values

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

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script returns the wrong values

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}

Anonymous
Not applicable

Re: Velocity Script returns the wrong values

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

Re: Velocity Script returns the wrong values

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

Anonymous
Not applicable

Re: Velocity Script returns the wrong values

Hi Sanford Whiteman,

when is said "param no. 5", i meant article no. 5... 😕

Our newsletter is always 5 articles long, for each article URL there's a different token.

The problem I've experienced was that all of the links pointed to the last article (article no. 5). In preview mode, it all works as expected.

Anyway, with your help, i've found a workaround 🙂

I just created unique parameters for each token and didn't use the same param name in different tokens. Now it all works well.

BTW,

didnt closed the <a> tag in "define", but i close it in the HTML.  Still works 🙂

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script returns the wrong values

Cool, not reusing VTL variables in links is key, as you can see!

P.S. That unclosed tag may not work permanently. Marketo's HTML lexer is pretty lazy -- it thinks <a:tag> is an <a>, which is actually really fortunate for some cases -- but if it ever gets tightened up, the link would break. Of course plenty of other things will probably break in the meantime.