Hi,
I have been having an issue with links in some of our emails. The link contains an important parameter for an id that can be in two different fields but i don't know which, so I check both in the script token and get the first non-empty match.
The link inside the email looks like this:
The script token looks like this:
## Returns the first populated Au Pair Id / Au pair
## from either the Lead, Contact, Account or Opportunity objects
##
##
## Define possible variables
## // Au Pair Number should be used instead of Au Pair ID,
## // since Au Pair ID can be different in Tellus sometimes
#set($AupairNumber = "initial value")
#set($empty = "")
##
## Determine the first not empty value
#if(${lead.AP_Au_Pair_Number__c} != $empty)
#set($AupairNumber=${lead.AP_Au_Pair_Number__c})
#elseif(${company.AP_Au_Pair_Number__c} != $empty)
#set($AupairNumber=${lead.Au_pair_number__c})
#elseif(${OpportunityList.get(0).Au_Pair__c} != $empty)
#set($AupairNumber=${OpportunityList.get(0).Au_Pair__c})
#else
#set($AupairNumber = "unknown")
#end
##
## Return not empty value
$AupairNumber
And in preview renders correctly (valid url and 'apid' correclty rendered):
But the real email either redirects to this in gmail when I click, before I replaced the first regular token with a splled-out url (url invalid)
Or this after replacing the initial regular token (url valid but 'apid' is now empty)
Any insights into why this is happening? I deactivated link tracking as well for this link, since I already noticed that breaks links with script tokens
Perhaps you @SanfordWhiteman ?
Thanks!
Solved! Go to Solution.
Shouldn't compare to empty (nor use the == operator at all!) but rather use isEmpty():
## Returns the first populated Au Pair Id / Au pair
## from either the Lead, Contact, Account or Opportunity objects
##
##
## Define possible variables
## // Au Pair Number should be used instead of Au Pair ID,
## // since Au Pair ID can be different in Tellus sometimes
#set($AupairNumber = "initial value")
##
## Determine the first not empty value
#if( $lead.AP_Au_Pair_Number__c.isEmpty() )
#set( $AupairNumber = $lead.AP_Au_Pair_Number__c )
#elseif( $company.AP_Au_Pair_Number__c.isEmpty() )
#set( $AupairNumber = $lead.Au_pair_number__c )
#elseif( $OpportunityList.get(0).isEmpty() )
#set( $AupairNumber = $OpportunityList.get(0).Au_Pair__c )
#else
#set( $AupairNumber = "unknown" )
#end
##
## Return not empty value
$AupairNumber
But that's not the problem — the prob is you must output the entire link, from <a> through </a> inclusive from Velocity. Links made partially from Velocity output aren't aren't supported.
Shouldn't compare to empty (nor use the == operator at all!) but rather use isEmpty():
## Returns the first populated Au Pair Id / Au pair
## from either the Lead, Contact, Account or Opportunity objects
##
##
## Define possible variables
## // Au Pair Number should be used instead of Au Pair ID,
## // since Au Pair ID can be different in Tellus sometimes
#set($AupairNumber = "initial value")
##
## Determine the first not empty value
#if( $lead.AP_Au_Pair_Number__c.isEmpty() )
#set( $AupairNumber = $lead.AP_Au_Pair_Number__c )
#elseif( $company.AP_Au_Pair_Number__c.isEmpty() )
#set( $AupairNumber = $lead.Au_pair_number__c )
#elseif( $OpportunityList.get(0).isEmpty() )
#set( $AupairNumber = $OpportunityList.get(0).Au_Pair__c )
#else
#set( $AupairNumber = "unknown" )
#end
##
## Return not empty value
$AupairNumber
But that's not the problem — the prob is you must output the entire link, from <a> through </a> inclusive from Velocity. Links made partially from Velocity output aren't aren't supported.
Sorry Sanford, now that I realize what I need is a "isNotEmpty()" if something like that exists. I had a lot of trouble with VTL documentation to find the correct way to say "is empty" or is null.
There are different answers here:
https://cwiki.apache.org/confluence/display/VELOCITY/VelocityNullSupport
#if ($foo == null) foo is null #end
I don't think this worked at all in Marketo, feels like a different version of VTL ?
https://cwiki.apache.org/confluence/display/VELOCITY/CheckingForNull
In here the approach was similar, but I think it also didn't work for me
In the official documentation I have trouble finding how to check for null
https://velocity.apache.org/engine/1.7/vtl-reference.html
and also they mention this
but you say not to use "==" so that left me quite confused
Thanks so much for going over it Sanford!
I'll redo things according to your feedback and see.