SOLVED

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

Go to solution
acardelle
Level 1

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

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

Screenshot 2023-11-07 at 8.51.05 PM.png

 

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script used in a URL producing white space (%0 in URL)

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.

View solution in original post

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script used in a URL producing white space (%0 in URL)

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.

acardelle
Level 1

Re: Velocity script used in a URL producing white space (%0 in URL)

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

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

 

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

Re: Velocity script used in a URL producing white space (%0 in URL)

Glad to hear you're using those resources! You get what I mean about the trailing CR, right?
acardelle
Level 1

Re: Velocity script used in a URL producing white space (%0 in URL)

I believe so! It's because of the line break, the CR then produces that space, signified by the "%0D" in the URL correct?

 

And as an update, I worked with my colleague following your instructions, and we got the script to work! Thank you! 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script used in a URL producing white space (%0 in URL)


I believe so! It's because of the line break, the CR then produces that space, signified by the "%0D" in the URL correct?

Yes, the line break is Unicode U+000D, then that gets encoded as %0D.

acardelle
Level 1

Re: Velocity script used in a URL producing white space (%0 in URL)

Amazing! I'm understanding now so much better. I appreciate you taking the time to explain @SanfordWhiteman . This is pretty exciting stuff for me. I appreciate being able to apply new knowledge and it's fulfilling once I can see where/how I went wrong, and being able to understand it, and correct it.