Velocity script on Custom Object | Community
Skip to main content
Kacper_Gawlik1
Level 2
August 9, 2019
Question

Velocity script on Custom Object

  • August 9, 2019
  • 1 reply
  • 4718 views

Hello!

I was looking for this within the forum but could not find ideal solution for my issue.

I am using following script on pulling out particualr content however, I wanted to show default content when contact is not in my CO

#foreach($content in $nurture_COList)
#set($url = $content.url)
#set($urlLength = $url.length() - 0) ## gets the length of the url
#set($trimUrl = $url.substring(8,$urlLength)) ## takes the sub-string starting after https://
<p><strong><a href="https://${trimUrl}">${content.title}</a></strong><br />
</p>
#end‍‍‍‍‍‍‍‍‍‍‍‍‍‍

$content is a field that is pushed by the external provider that pushed data into it.

There is also MarketoId field to which I want to refer when it's empty then load default content i.e.

#foreach($content in $nurture_COList)
#set($url = $content.url)
#set($urlLength = $url.length() - 0) ## gets the length of the url
#set($trimUrl = $url.substring(8,$urlLength)) ## takes the sub-string starting after https://
<p><strong><a href="https://${trimUrl}">${content.title}</a></strong><br />
</p>
#if $(nurture_COList.get(0).marketoId.isEmpty())
My Static Value
#end
#end

But that does not seem to work.

Anyone is able to help me withi this? Appreciate any insight!

Thanks,
Kacper

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

1 reply

SanfordWhiteman
Level 10
August 9, 2019

Right now, you're checking if the first record in the CO has a certain value.

You want to check if the current record has that value. Otherwise you're checking the same thing on every turn of the loop. Doesn't make sense.

Also, String.substring is overloaded. You can pass only the startIndex. You don't need the endIndex.

#foreach( $content in $nurture_COList )
#set( $url = $content.url )
## takes the sub-string starting after https://
#set( $trimUrl = $url.substring(8) )
<p><strong><a href="https://${trimUrl}">${content.title}</a></strong><br /></p>
#if( $content.marketoId.isEmpty() )
My Static Value
#end
#end‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Kacper_Gawlik1
Level 2
August 9, 2019

Hi Sanford,

What I actually want to check is if contact is on CO to show the content in <p></p> and if not, show static value.

${idio_Nurture_ArticleList.get(0).marketoId}
#foreach($content in $nurture_COList)
#set($url = $content.url)
#set($urlLength = $url.length() - 0) ## gets the length of the url
#set($trimUrl = $url.substring(8,$urlLength)) ## takes the sub-string starting after https://
<p><strong><a href="https://${trimUrl}">${content.title}</a></strong><br />
</p>
#if $(nurture_COList.get(0).marketoId.isEmpty())
My Static Value
#end
SanfordWhiteman
Level 10
August 9, 2019

That's broken code -- and you changed the nesting.

Can you please describe your requirements without using code?