Velocity script used in a URL producing white space (%0D in URL - Carriage Return) | Community
Skip to main content
New Participant
November 8, 2023
Solved

Velocity script used in a URL producing white space (%0D in URL - Carriage Return)

  • November 8, 2023
  • 1 reply
  • 2567 views

Hello community!

I was wondering if anyone has experienced this when writing a velocity script in marketo. The use case here is that we would like to tie a subscription back to the contact ID in salesforce, when a contact fills out a survey (which in turn, a few things get populated such as the subscription (SID), contact ID (CID) and account ID (AID) all in the same URL path of the survey (which in turn, is integrating back to Salesforce with this information). The script seems to work for the most part, but we are having issues where there is white space (%0) right before the actual SID (screenshot below). 

 

Here is the script we are using:

##setting some global date stuff (probably not all necessary)
#set($defaultTimeZone = $date.getTimeZone().getTimeZone("America/Los_Angeles"))
#set($defaultLocale = $date.getLocale())
#set($calNow = $date.getCalendar())
#set($ret = $calNow.setTimeZone($defaultTimeZone))
#set($calConst = $field.in($calNow))
## Set the date 90 days prior
$calNow.add($calConst.DATE, -90)
## Create subscription id var
#set($subscription_id = "")
## Create a variable to track the most recent subscription date
#set($mostRecentDate = $date.toDate('yyyy-MM-dd', '1900-01-01'))
## Loop through influencers looking for dates older than 90 days and setting the latest Sub ID
#foreach($influencer in $sorter.sort($Influencer__cList, 'created_date:desc'))
#set($influencerCreatedDate = $date.toDate('yyyy-MM-dd', $influencer.CreatedDate))
#if($date.difference($calNow, $influencerCreatedDate).days < 0)
#if($influencerCreatedDate.after($mostRecentDate))
#set($name = $influencer.Subscription__c)
#set($subscription_id = $name.replaceAll("\\s+","").trim())
#end
#end
#end
##Print Subscription ID
$subscription_id

 

I read up on @sanfordwhiteman blogs https://blog.teknkl.com/buffer-strip-swallow-unwanted-whitespace-velocity-tokens/ as well as a few other posts in the marketo community, but could not seem to find out what we were doing wrong. I would say I am still a novice with script, so any help/advice is greatly appreciated. Apologies in advance if I am posting in the wrong location, or missing any information that would help explain the issue better. I would be happy to provide. Thank you kindly. 

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

It’s not %0, it’s %0D (Carriage Return).

 

You have a line break at the end of the last line of this code, don’t you? That’s the obvious source.

 

But the bigger problem is trying to compose links part-in, part-out of Velocity. You should be emitting the entire <a> tag from Velocity, through the closing </a>. That’s the supported syntax.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
November 8, 2023

It’s not %0, it’s %0D (Carriage Return).

 

You have a line break at the end of the last line of this code, don’t you? That’s the obvious source.

 

But the bigger problem is trying to compose links part-in, part-out of Velocity. You should be emitting the entire <a> tag from Velocity, through the closing </a>. That’s the supported syntax.

acardelleAuthor
New Participant
November 8, 2023

Thank you @sanfordwhiteman ! I was reading through the community to try to get more knowledge (some you commented on as well!):

https://nation.marketo.com/t5/product-discussions/velocity-script-link-is-getting-quot-0d-quot-added-at-the-end/td-p/309205 

https://nation.marketo.com/t5/product-discussions/velocity-script-not-printing-working-hyperlink/td-p/329288 

 

I found those two very informative.

 

Also, your blog on velocity in general (which I'm continuing to read and catch up on - thank you for contributing to the community great knowledge and resources):

https://blog.teknkl.com/tag/velocity/

 

I will update the subject of my post according to your last comment on %0D and not %0 signifying Carriage Return. Thank you so much again. 

SanfordWhiteman
New Participant
November 8, 2023
Glad to hear you're using those resources! You get what I mean about the trailing CR, right?