6 Replies Latest reply on Jun 16, 2017 8:10 AM by Phillip Wild

    <a href> with scripting not working

    Phillip Wild

      I'm having some trouble with an email script passing through a URL.

       

      #set($dossierURL = "www.gadventures.com/trips/${trips_cList.get($listlength).dossier}" )

      #set($imageLink = ${trips_cList.get($listlength).dossierImageURL} )

       

      <a href="https://$dossierURL/" style="color: #47268d; font-weight: bold; font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> <img src="http://$imageLink" width="600" border="0" class="deviceWidth" style="display:block;border-width:0;-ms-interpolation-mode:bicubic;"> </a>

       

      The image passes through just fine, but the link goes to something like this:

       

      https://%24%7Bmy.vdossier_url_1987005%7D/?utm_source=&utm_medium=email&utm_campaign=&mkt_tok=eyJpIjoiTkRkalpXUmxNREJpTjJJMiIsInQiOiJPaE43MCtleHU5c0ZpV05WRHZkbTlcL1o2Y2ZMZkdrMnRKczFoTWdpUWdCc01QUDdMXC95RGczMTRcL3FqcGFuc1Nvb1draU05M0h3V2pDOWVhRFdkYlNWUT09In0%3D

       

      Clearly the token is not translating properly, but what's even more confusing is that there are extra parameters on the URL that are on the end of the URL (?utm_source etc). Is this possibly because I have other email script tokens using the same variables in my email program? That's the only explanation I can think of.

       

      Thanks, Phil

        • Re: <a href> with scripting not working
          Sanford Whiteman

          Use formal notation when outputting: ${dossierURL} and ${imageLink}.

          1 of 1 people found this helpful
            • Re: <a href> with scripting not working
              Phillip Wild

              Thanks again Sanford!

              • Re: <a href> with scripting not working
                Phillip Wild

                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&amp;utm_medium=email&amp;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
                    #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.

                    1 of 1 people found this helpful
                      • Re: <a href> with scripting not working
                        Phillip Wild

                        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!