I have an email where I need to display a URL that is stored in a field on the Opportunity. I successfully wrote a Velocity script that populates a token with this field from the most recent active opportunity. However, I am running into the same problem that this post discusses. Because the field is a URL, the email script is not always compiling. I was seeing the issue in about 50% of clicks, that the link actually shows as the script itself. At first I wanted to solve it by transferring the field from the opportunity to the person whenever the field was updated. But that did not work.
Summary: I am pulling a URL from an opportunity using a script token. I use it in an email link like this: https://{{my.scripttoken}}. Tracking the link breaks how this URL is shown in the actual email. Any suggestions?
Solved! Go to Solution.
That article is almost completely incorrect and should be removed. I’ll work on that.
The actual (and only) problem with links in Velocity is when you reference the same Velocity variable in multiple URLs, expecting it to have different values. That doesn’t work, I have a whole blog post about the crazy thing you need to do to solve it.
But if you’re only outputting a single URL, then simply ensure you output the entire <a> tag from Velocity. That means the opening <a> through closing </a> and everything in-between.
Then insert the {{my.token}} in the appropriate location in the email. Don’t do https://{{my.token}} when the {{my.token}} is a Velocity token.
That article is almost completely incorrect and should be removed. I’ll work on that.
The actual (and only) problem with links in Velocity is when you reference the same Velocity variable in multiple URLs, expecting it to have different values. That doesn’t work, I have a whole blog post about the crazy thing you need to do to solve it.
But if you’re only outputting a single URL, then simply ensure you output the entire <a> tag from Velocity. That means the opening <a> through closing </a> and everything in-between.
Then insert the {{my.token}} in the appropriate location in the email. Don’t do https://{{my.token}} when the {{my.token}} is a Velocity token.
Thank you for this! I was able to use this to update my script and it now appears to work.
#set( $defaultLink = "www.example.com/" )
#foreach( $opportunity in $OpportunityList )
#if( $opportunity.salesStage.equals("Active") )
#set( $OutputURL = $opportunity.Opportunity-URL-value )
#break
#end
#end
#set( $OutputURL = $display.alt($OutputURL, $defaultLink) )
<a href="https://${OutputURL}">Click here</a>
I thought I had this working but it is broken again. @SanfordWhiteman do you mind doing a double-check of this from a Velocity script perspective?
The current output people are getting is "https://${OutputURL}" rather than the actual URL.
Are you testing with a real email, not a sample? Also, you only have the {{my.token}} once in the email, right?
The code itself looks OK to me at a glance.
@SanfordWhiteman Thank you so much for taking the time to review. Yes, I am testing with real emails, and yes, the token is only used once.
When I include the lines for the default link, everyone seems to get the default link. When I remove those, the link comes in with the token instead of the actual link. I am still experimenting, but not sure where it is going wonky.
Just to follow up on this, it turns out the capitalization in API names was different between sandbox and production, which is why I was having issues. The code was perfect. Thank you again for the review!