Skip to main content
Michael_Florin-2
Level 10
Sep 8, 2022 5:28 PM UTC
Solved

Why is Velocity outputting a blank in my link?

Hello all,

 

I took over an instance where somebody obviously followed Sanford's blog here:

https://blog.teknkl.com/marketo-json-fields-in-velocity/

 

And most things work beautifully. But one thing is not and that is this piece:



#if( $TriggerObject.flexibileFormContent.isEmpty() )
#set( $TriggerObject.flexibileFormContent = '[]' )
#end
#set( $CoursesSelected = '#set( $CoursesSelected = ' + $TriggerObject.flexibileFormContent + ' )' )
#evaluate( $CoursesSelected )
<a href="https://${Course[0].TeamsLink}">Teilnahme-Link</a>

 Here's what this script creates on the email:

https:// Teilnahme-Link

 

Where does this blank after // come from that obviously kills my link? ${Course[0].TeamsLink} would render a link not starting with https://

Thanks!
Michael

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
Sep 11, 2022 9:20 PM UTC

There aren’t any control characters/whitespace in there, if that’s a direct copy & paste. But I also can’t reproduce the output you’re seeing — it all looks fine to me when I simulate it with:

#define( $flexibileFormContent ) [{"EventId":"MIC-M365F-E-220311","EventName":"xxx","Language":"German","EventDate":"2022-03-11 09:00 - 16:00 CET","TotalPriceWithCurrency":"3,890.00 EUR","TeamsLink":"teams.microsoft.com/l/meetup-join/19%3ameeting_ZGI2NTA2ZjEtNmRkZi00NTlkLTk5OTQtNmQ0OTMxZDQ0Y2Ex%40thread.v2/0?context=%7b%22Tid%22%3a%22e8ac1d3f-5424-46b4-8d41-7076","InstructorLink":"https://www.example.com","LinkForRequestingExamVoucher":"https://forms.office.com/r/aaaaa"}] #end #set( $TriggerObject = { "flexibileFormContent" : $flexibileFormContent.toString() } ) #set( $CoursesSelected = '#set( $CoursesSelected = ' + $TriggerObject.flexibileFormContent.toString() + ' )' ) #evaluate( $CoursesSelected ) <a href="https://${CoursesSelected[0].TeamsLink}">Teilnahme-Link</a>

 

But do note that I’m using the (correct) ${CoursesSelected[0].TeamsLink} where you had ${Course[0].TeamsLink}. Is it possible that you’re referring to some other copy of the data stored in another var?

5 replies

SanfordWhiteman
User Group Leader
User Group Leader
Sep 8, 2022 7:12 PM UTC

Have to see your actual data to know for sure. Is that a space (as in U+0020) or is it actually a line break (rendered in HTML as a space)?

Translate
Michael_Florin-2
Level 10
Sep 9, 2022 6:56 AM UTC

Thank you for helping, Sanford!

 

Here's how the entry in my Custom Object looks like:

 

[{"EventId":"MIC-M365F-E-220311","EventName":"xxx","Language":"German","EventDate":"2022-03-11 09:00 - 16:00 CET","TotalPriceWithCurrency":"3,890.00 EUR","TeamsLink":"teams.microsoft.com/l/meetup-join/19%3ameeting_ZGI2NTA2ZjEtNmRkZi00NTlkLTk5OTQtNmQ0OTMxZDQ0Y2Ex%40thread.v2/0?context=%7b%22Tid%22%3a%22e8ac1d3f-5424-46b4-8d41-7076","InstructorLink":"https://www.example.com/","LinkForRequestingExamVoucher":"https://forms.office.com/r/aaaaa"}]

 

And here's the payload in Postman:

 

            "flexibileFormContent": "[{\"EventId\":\"MIC-M365F-E-220311\",\"EventName\":\"xxx\",\"Language\":\"German\",\"EventDate\":\"2022-03-11 09:00 - 16:00 CET\",\"TotalPriceWithCurrency\":\"3,890.00 EUR\",\"TeamsLink\":\"teams.microsoft.com/l/meetup-join/19%3ameeting_ZGI2NTA2ZjEtNmRkZi00NTlkLTk5OTQtNmQ0OTMxZDQ0Y2Ex%40thread.v2/0?context=%7b%22Tid%22%3a%22e8ac1d3f-5424-46b4-8d41-7076\",\"InstructorLink\":\"https://www.example.com\",\"LinkForRequestingExamVoucher\":\"https://forms.office.com/r/aaaaa\"}]",

 I really can't see if there are linebreaks or spaces somewhere in there.

Translate
SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
Sep 11, 2022 9:20 PM UTC

There aren’t any control characters/whitespace in there, if that’s a direct copy & paste. But I also can’t reproduce the output you’re seeing — it all looks fine to me when I simulate it with:

#define( $flexibileFormContent ) [{"EventId":"MIC-M365F-E-220311","EventName":"xxx","Language":"German","EventDate":"2022-03-11 09:00 - 16:00 CET","TotalPriceWithCurrency":"3,890.00 EUR","TeamsLink":"teams.microsoft.com/l/meetup-join/19%3ameeting_ZGI2NTA2ZjEtNmRkZi00NTlkLTk5OTQtNmQ0OTMxZDQ0Y2Ex%40thread.v2/0?context=%7b%22Tid%22%3a%22e8ac1d3f-5424-46b4-8d41-7076","InstructorLink":"https://www.example.com","LinkForRequestingExamVoucher":"https://forms.office.com/r/aaaaa"}] #end #set( $TriggerObject = { "flexibileFormContent" : $flexibileFormContent.toString() } ) #set( $CoursesSelected = '#set( $CoursesSelected = ' + $TriggerObject.flexibileFormContent.toString() + ' )' ) #evaluate( $CoursesSelected ) <a href="https://${CoursesSelected[0].TeamsLink}">Teilnahme-Link</a>

 

But do note that I’m using the (correct) ${CoursesSelected[0].TeamsLink} where you had ${Course[0].TeamsLink}. Is it possible that you’re referring to some other copy of the data stored in another var?

Translate