Skip to main content
Level 1
Oct 10, 2022 9:43 AM UTC
Solved

Velocity Script not printing working hyperlink

I am having an issue with the following code:

 

 

##set the variable referrer to the last Marketo Form URL and set to lowercase #set( $referrer = ${lead.anyvalue.toLowerCase()}) ##check value #if( $referrer.contains("abc")) #set( $url = "www.abc.com") #set( $name = "abc") ##second check #elseif( $referrer.contains("xyz")) #set( $url = "www.xyz.com") #set( $name ="xyz") ##fallback #else #set( $url = "www.foo.com") #set( $name ="foo") #end ##print Outcome <a href="https://$url">$name</a>

 

 

 

So the code works in basis.

The $name variable works and displays as expected in all cases. The url doesn't work. But only doens't work for the dependent values, the fallback value always shows.

 

After some testing, I found that if I take the $url out of the href tag and paste them as seperate lines, it works just fine. But, whenever I try to add it to the href tag, it breaks. The output is like this on the URL:

https://%24url/?mkt_tok=tokenhere

 

Hope anyone can help me out on this because it's driving me nuts. Looking at the documentation (and forum) this should work but clearly doesn't.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Michael_Florin-2
Michael_Florin-2Accepted solution
Level 10
Oct 10, 2022 3:03 PM UTC

Have you tried using formal notation? Looking at my script library, I believe that's what Sanford taught us all to do. 🙂

<a href="https://${OutputURL}">Click here</a>



3 replies

Michael_Florin-2
Michael_Florin-2Accepted solution
Level 10
Oct 10, 2022 3:03 PM UTC

Have you tried using formal notation? Looking at my script library, I believe that's what Sanford taught us all to do. 🙂

<a href="https://${OutputURL}">Click here</a>



Translate
Level 1
Oct 11, 2022 3:29 PM UTC

Thanks to both. This works like a charm!

Translate
SanfordWhiteman
User Group Leader
User Group Leader
Oct 10, 2022 8:25 PM UTC

What Michael said. But also your first line should be using simple notation:

#set( $referrer = $lead.anyvalue.toLowerCase() )

 

Use simple notation when calling methods. Use formal notation when creating output or interpolating strings.

Translate