Velocity Script with Custom Object and lead.id

Christina_Kyril
Level 1

Velocity Script with Custom Object and lead.id

Having troubles with velocity scripting on Custom Objects. Looking to do a table that provides dynamic content for the text as well as links that are able to be referenced for that text.

 

Here is the script that has been built so far setting the parameters for our utm string as well:

## Set UTM Parameter Values

#set( $progName = "name of program here" )
#set( $emailID = "xxxxx" )
#set( $leadID = $lead.id )
#set( $utmOffer = "offer" )
#if($myCustomObject.customUrl1)
#set($url = $myCustomObject.customUrl1)
<a href="https://${url}&utm_source=marketo&utm_medium=email&utm_campaign=${progName}&utm_offer=${utmOffer}&utm_content=assetID:${emailID}&utm_term=mkid:${leadid}
">$myCustomObject.customString2</a>##
#end

 

Links hosted on Marketo (Design Studio) are working as they should. Other links non-Marketo hosted are not rendering and breaking somewhere with the mktg-alert tracking wrapper.

 

Additionally, since lead.id is not a field I am able to choose from the Custom Object Tree bc it's not a system token (and we need to use that as it's unique due to dupes in the system) - I tried the marketosend.leadid script and still can't get that piece to work.

 

Can anyone help troubleshoot?

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script with Custom Object and lead.id

You can't simply append "&" to any URL and create a valid query string.

 

You'd have to know that the URL already had a query string, even an empty one. That is, https://www.example.com/? and https://www.example.com/?key=value both already have a query string. Just plain https://www.example.com/ can't have "&" appended, it'll be a broken URL.

 

In addition, string variables like $progName need to be URL-encoded before being added to URLs. You want ${esc.url($progName)}, not ${progName}. Otherwise, using a reserved character in the string value (which Marketo will never stop you from doing, it's free text) will result in the wrong URL.