SOLVED

Why is Velocity outputting a blank in my link?

Go to solution
Michael_Florin
Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Why is Velocity outputting a blank in my link?

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?

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Why is Velocity outputting a blank in my link?

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

Michael_Florin
Level 10

Re: Why is Velocity outputting a blank in my link?

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.

Tags (1)
SanfordWhiteman
Level 10 - Community Moderator

Re: Why is Velocity outputting a blank in my link?

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?

Michael_Florin
Level 10

Re: Why is Velocity outputting a blank in my link?

Thanks again, Sanford! Works for me too now. I have no clue how that ${Course[0].TeamsLink} got into my script...

 

 

Tags (1)
SanfordWhiteman
Level 10 - Community Moderator

Re: Why is Velocity outputting a blank in my link?

Great!