Email Script Token breaking hyperlink | Community
Skip to main content
Taylor_McCarty
Level 3
August 8, 2019
Solved

Email Script Token breaking hyperlink

  • August 8, 2019
  • 1 reply
  • 7138 views

So I have a scripting token that is pulling a unique URL off the Opportunity object and I want to then use that URL for the hyperlink on the button in the email. However something is breaking the HTML code from the button and ends up displaying the URL and then the broken code for the button. Below is a screenshot of what it is doing, I had to block out the URL because it's a unique link related to each opportunity. 

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 SanfordWhiteman

Not sure if this will help, but here is my code, just edited a little so that its hopefully not showing anything that my legal team would get me in trouble for displaying. I am sure this code isn't very sophisticated and could be written way better, but this is the best I got from teaching myself this stuff and reusing code from previously build tokens from someone else that is no longer at the company.

#foreach( $o in $sorter.sort(${OpportunityList}, "MarketoCreatedAt:desc") )
#if( $oppFound == 0 && $o.Company_Name__c && $o.Company_Name__c == "Name of Company" )
#set ( $oppFound = 1 )
#if( $o.E_Comm_Link__c == "No E-Comm Link")
https://www.generic-landing-page.com##
## <br>No E-Comm Link##
#elseif( ${lead.Number_of_Opportunities} == 1)
## #set( $b = $o.E_Comm_Link__c.replace("https://", "") )
## $b <br>##
## <a href="$o.E_Comm_Link__c">Click me</a><br>##
$o.E_Comm_Link__c##
## <br>Has E-comm link##
#else
https://www.generic-landing-page.com##
## <br>Greater Than One Opp##
#end
#end
#end
#if ( $oppFound == 0 )
https://www.generic-landing-page.com##
#end

Your code should be refactored more like so:

#set( $interestingCompanyName = "CompanyCo, Inc." )
#set( $defaultLink = "www.example.com/generic-landing-page" )
#set( $EXC_LINK_NO_LINK = "No E-Comm Link" )
#foreach( $o in $sorter.sort( $OpportunityList, "MarketoCreatedAt:desc") )
#if( $o.Company_Name__c.equals($interestingCompanyName) )
#if( !$o.E_Comm_Link__c.equals($EXC_LINK_NO_LINK) && $lead.Number_of_Opportunities.equals(1) )
#set( $outputLink = $o.E_Comm_Link__c )
#end
#break
#end
#end
#set( $outputLink = $display.alt($outputLink, $defaultLink) )
<a href="https://${outputLink}">Click Me</a>

But still, the relevant change is that the entire A is output.

Naturally I'm assuming you don't have any typos in field names and all the fields are checked off in the tree.

1 reply

SanfordWhiteman
Level 10
August 8, 2019

You haven't supplied enough information to troubleshoot -- there isn't even any code in your post!

When using Velocity, you must output the entire link -- from the opening <a> to closing </a> -- in Velocity.

Taylor_McCarty
Level 3
August 8, 2019

I'm reluctant to output the code because it has some other sensitive information that I am not sure our legal team would allow to be displayed.

However I am not making the link in the velocity script. I am just asking that it return the URL. Then I am just adding the token into the hyperlink, so my email looks like this:

<a href="{{my.OPP_Ecomm_Link}}">Link</a>

SanfordWhiteman
Level 10
August 8, 2019

You need to follow the standard links-in-Velocity  guideline I noted.