Dynamic links custom objects breaking | Community
Skip to main content
Level 3
Oct 3, 2019 3:51 PM UTC
Question

Dynamic links custom objects breaking

Hi,

Links are breaking when trying to pull from custom object, the code is within a FOR LOOP - for testing purposes I have reduced the code. Anyone have any ideas why the links are breaking?

Working URL outside FOR/IF LOOP, pulling link from custom object(DynamicCustomObjectList) : ${DynamicCustomObjectList.get(1).URL_1}

Links not working when inside FOR loop:

#foreach( $co_record in $DynamicCustomObjectList)
   <a href="https://${co_record.URL_1}">CLICK ME</a>
<br>
   <a href="https://uk.website.com/${co_record.URL_1}">CLICK ME TO</a>
<br>
   <a href="https://$co_record.URL_1">CLICK ME AGAIN</a>

#end

Output link break: https://%24%7Bco_record.url_1%7D/?mkt_tok=eyJpIjoiTkRoak5qTTNNREl6WVRaaSIsInQiOiJDVVwvZmlrSWpzUEgrdjlYV2VvMENHME5PZG0xcThHQVd3TEp4Y3l4WEJERXUrMlwvTUQ0TjdqNGE1WTNGa1RPUUgwbDh2VFlKeWc5dTdRMEM3YXRPZFd2VlVyUGlPSE4zc25WRCtiQThjWHg4b1FzcFB0b2VRUStsMjVwZVBlTGVvIn0%3D

The code is in an email script token, which then is added to a snippet and from that called into an email.

Thanks,

Haroon

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

8 replies

HaroonRaAuthor
Level 3
Oct 3, 2019 4:22 PM UTC

At the moment I'm not totally comfortable with Velocity scripting.

Is it possible to help with the example code provided?

Translate
SanfordWhiteman
Level 10
Oct 4, 2019 2:56 AM UTC
#foreach( $co_record in $DynamicCustomObjectList )
#set( $currentURLNoProto = $co_record.URL_1 )
#foreach( $link in [1..3] )
#evaluate( "${esc.h}set( ${esc.d}URL_${foreach.parent.count}_${foreach.count} = ${esc.d}currentURLNoProto )" )
#end
#end
#if( $URL_1_1 )
<a href="https://${URL_1_1}">CLICK ME</a>
#end
#if( $URL_1_2 )
<a href="https://uk.website.com/${URL_1_2}">CLICK ME TOO</a>
#end
#if( $URL_1_3 )
<a href="https://${URL_1_3}">CLICK ME AGAIN</a>
#end
#if( $URL_2_1 )
<a href="https://${URL_2_1}">CLICK ME</a>
#end
#if( $URL_2_2 )
<a href="https://uk.website.com/${URL_2_2}">CLICK ME TOO</a>
#end
#if( $URL_2_3 )
<a href="https://${URL_2_3}">CLICK ME AGAIN</a>
#end‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

As noted in the blog post, because of Marketo's peculiarities when introspecting the data for links, you must preallocate individual variables (not properties) for each possible link.

Translate
HaroonRaAuthor
Level 3
Oct 4, 2019 9:55 AM UTC

Thanks Sanford! That helped loads.

There is a little issue, I have six links in the custom object to pick up but the code above only pulling the same link for each.

 ##set($co_record.URL_1 = $DynamicCustomObjectList.URL_1)
##set($co_record.URL_2 = $DynamicCustomObjectList.URL_2)
##set($co_record.URL_3 = $DynamicCustomObjectList.URL_3)
##set($co_record.URL_4 = $DynamicCustomObjectList.URL_4)
##set($co_record.URL_5 = $DynamicCustomObjectList.URL_5)
##set($co_record.URL_6 = $DynamicCustomObjectList.URL_6)

Is there a way to pull each link?

Thanks again,

Haroon

Translate
SanfordWhiteman
Level 10
Oct 3, 2019 4:04 PM UTC