-
Re: <a href> with scripting not working
Sanford Whiteman May 21, 2017 12:45 PM (in response to Phillip Wild)1 of 1 people found this helpfulUse formal notation when outputting: ${dossierURL} and ${imageLink}.
-
Re: <a href> with scripting not working
Phillip Wild May 22, 2017 6:24 AM (in response to Sanford Whiteman)Thanks again Sanford!
-
Re: <a href> with scripting not working
Phillip Wild May 22, 2017 1:39 PM (in response to Sanford Whiteman)Hi Sanford
I might have to revise this slightly...So here's the code I used:
#set ($listlength = ${List.size()})
#set ($listlength = $listlength - 1 )
<a href="https://www.gadventures.com/trips/${List.get($listlength).dossier}/?utm_source=Consumer_Transactional&utm_medium=email&utm_campaign=Sweepstakes" style="color: #47268d; font-weight: bold; font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> <img src="http://${List.get($listlength).dossierImageURL}" width="600" border="0" class="deviceWidth" style="display:block;border-width:0;-ms-interpolation-mode:bicubic;" alt="G Adventures"> </a>
Note I removed the line which sets the variables before I pass them through to the URL. I found using your solution above that using the notation ${List.get($listlength).dossier}/ works, but annoyingly that seems to destroy my URL parameters, and it also removes the Marketo tracking. Why? Based on the docs I've read around scripting in the Developers site, the notation <a href="https://www.example.com/${dossier}" should work just fine.
On a different note, I've found that when I add a new custom object to a lead profile, it's not changing the output of this script - it remains the same. Any tricks I need to know around this? Shouldn't the creation of a new custom object on the List object I'm referencing above mean that my code is using the latest entry? I feel like I've used this before in the past without issue.
Thanks again.
-
Re: <a href> with scripting not working
Sanford Whiteman May 23, 2017 12:50 AM (in response to Phillip Wild)1 of 1 people found this helpful#set ($listlength = $listlength - 1 )
That's really fragile. I'd do
#set( $lastIndex = $math.sub(listlength,1) )
The Velocity parser doesn't support the minus sign as much as you think it does.
Note I removed the line which sets the variables before I pass them through to the URL. I found using your solution above that using the notation ${List.get($listlength).dossier}/ works, but annoyingly that seems to destroy my URL parameters, and it also removes the Marketo tracking. Why? Based on the docs I've read around scripting in the Developers site, the notation <a href="https://www.example.com/${dossier}" should work just fine.
With links, I'd put as much as possible (except for the http:// or https://) in a single Velocity $reference.
Dunno offhand about the URL parameters disappearing, but put them inside the dynamic string and see what happens.
On a different note, I've found that when I add a new custom object to a lead profile, it's not changing the output of this script - it remains the same. Any tricks I need to know around this? Shouldn't the creation of a new custom object on the List object I'm referencing above mean that my code is using the latest entry? I feel like I've used this before in the past without issue.
It means you're using the last index in the array: that's as far as I'd go because the docs don't match up to reality on this one. I always sort the COs by date if I want to be sure to get the last one.
-
Re: <a href> with scripting not working
Phillip Wild Jun 5, 2017 6:05 PM (in response to Sanford Whiteman)Thanks again Sanford.
I've solved the URL parameters issue - it was because of a strange redirect on our website. I've removed the need for the redirect and it works just fine.
However, the size of the array is still giving me trouble. This line:
#set ($listlength = ${abandonedCart_cList.size()})
Always evaluates to 1, no matter how many are in the array. Even stranger, when I hardcode the number into a line like this, trying to get the second element:
#set( $hyperlink = "${array.get(1).variable}")
The email doesn't send. I'm guessing that it's because Marketo can't find the second element in that array. So it seems that listlength is always 1 because the size of the array is always 1.
I've checked this with a few different leads in Marketo (both with multiple elements in the custom object) and I keep getting 1. When I tried a different array (from a Salesforce custom object) with multiple values, that same line of code to check the size of the array outputs correctly - giving me 27 in one instance.
So what would be different about that array that is causing it to behave like this? I can see all Marketo Custom Object entries when I look in the Marketo lead records. Since the offending array is a Marketo Custom Object, and the one that works correctly is a Salesforce Custom Object, I'm guessing it's related to that. But why?
On your first point around the fragility of $listlength - 1, is this because Velocity imports everything as strings? Just for my knowledge.
Thanks in advance, again!
-
Re: <a href> with scripting not working
Phillip Wild Jun 16, 2017 8:10 AM (in response to Phillip Wild)Just to round this off, the above error around arrays is because I was using "Send Sample Email" instead of using a single flow action to test the scripting. Oops!
-
-
-
-