Velocity Scripting for URLs | Community
Skip to main content
New Participant
March 22, 2022
Solved

Velocity Scripting for URLs

  • March 22, 2022
  • 1 reply
  • 2757 views
I am hoping someone can help me with a velocity script question. In all transparency I am not a coder but working to understand.
  • I have a URL in a custom object.
  • The URL contains the full value including https://
  • I have a super basic velocity token pulling in that value. (The script literally only is this: ${cartsAndQuotes_cList.get(0).cartURL}.)
  • The problem I have is that I do not get clicks counted  when I put that token into my CTA in an email template 
  • I think I need a way for the velocity script to return the URL without the https:// portion (so I can add https:// in front of the token in the CTA)
Can anyone point me to a good reference for simple scripting that would help me to accomplish this?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Darshil_Shah1

I think below velocity script should help. The script removes the "https://"  from the CO field's value, protocol is then added in the <a> tag to enable the click links tracking.

 

#set( $fieldWithProtocol = $cartsAndQuotes_cList.get(0).cartURL) #set( $fieldWithoutProtocol = $fieldWithProtocol.replaceAll("^https://","") ) <a href="https://${fieldWithoutProtocol}">My Cart</a>

 

 

Hope this helps!

1 reply

Darshil_Shah1
Darshil_Shah1Accepted solution
Community Manager
March 22, 2022

I think below velocity script should help. The script removes the "https://"  from the CO field's value, protocol is then added in the <a> tag to enable the click links tracking.

 

#set( $fieldWithProtocol = $cartsAndQuotes_cList.get(0).cartURL) #set( $fieldWithoutProtocol = $fieldWithProtocol.replaceAll("^https://","") ) <a href="https://${fieldWithoutProtocol}">My Cart</a>

 

 

Hope this helps!

New Participant
September 12, 2022

I Tried the same code but it's not working for me.

Instead of populating opportunity field default value is getting populated.

 

Used Code :

<meta class="mktoString" default="en-us" id="fieldWithoutProtocol" mktomodulescope="false" mktoname="fieldWithoutProtocol" />

 

<tr>
<td align="left">
<div class="mktoText" id="fieldWithProtocol" mktoname="fieldWithProtocol">
#set( $fieldWithProtocol = $OpportunityList.get(0).Repayment_Personalized_URL__c) #set( $fieldWithoutProtocol = $fieldWithProtocol.replaceAll("^https://","") )" /&gt;
<a href="https://${fieldWithoutProtocol}">My Cart</a>
</div></td>
</tr>