background shape
background shape

SFMC RANT: Inline AMPScript mystery

Working with Salesforce Marketing Cloud, I’ve learned that you often need to try different workarounds until you achieve the desired result. To succesfully solve problems, it all depends on your experience and patience.

Recently, I did a significant amount of work with AMPScript and personalization and wrote many tips during these days. It seems that it does not matter the experience you have you always stuck somewhere everyday. Today for example, I discovered that when using inline AMPScript with the ‘iif’ function and ‘index of,’ you cannot use greater than or less than signs, as it will throw the following error, indicating that your parentheses are not matched.

Following AMPScript that is correctly written, will throw and error in email studio when previewing email.

%%[
SET @url = "https://google.com"
SET @queryParams = "a=1&b=2&c=3"
]%%
%%=redirectto(Concat(@ProductUrl1, IIF(IndexOf(@ProductUrl1, "?")>0,"&", "?"),@queryParams ))=%%

Following error can successfully mislead you into thinking that you’ve missed some parentheses.

But fear not, all the 340 parentheses are in place and looking sharp. Then, after a couple of hours of debugging and diving into the problems, when I put aside all my other responsibilities, like to pick kids up from preshool (don’t worry, I didn’t just joking), I finally had the ‘AHA!’ moment and remembered that I should try different variations of the same condition. I changed ‘>0’ to ‘!=0,’ and it started to work as intended. That is atleast what I thought.

%%[
SET @url = "https://google.com"
SET @queryParams = "a=1&b=2&c=3"
]%%
%%=redirectto(Concat(@url, IIF(IndexOf(@url, "?")!=0,"&", "?"),@queryParams ))=%%

I will spare you and say this workaround doesn’t work either, but the preview worked, which left me really confused and led to another 2 hours of juicy debugging. Now I am back to square one, after spending nearly one work day on it.

But now that I have invsted day of my life for this I will continue. And move away from inline ampscript and nicely prepare. But this time I was very cautious and knew that if email will not arrive that means only one, indexof does not like >gt;< lt; signs. And as I thought the email is rendered but not sent succesfully.

%%[
  SET @querySeparator = "?"
  IF IndexOf(@url, "?") > 0 THEN /* why? do I miss some comparison basics? :) */
    SET @url = "&"
  ENDIF
]%%

I suppose there is something hidden deep down into the AMPScript compiler, that is only known to the chosen ones.

Anyway, I will a log a case so they can have same fun as I had. Will come back with the answers 🙂

THE conclusion

The support team mentioned that, based on their logs, it appears that the text version was not created correctly. Until today, I had never considered the text version in connection with the possibility of it breaking the email. Perhaps it’s because it’s automatically generated, and you have no control over it. However, it seems that certain combinations of AMPscript will render correctly in the HTML version but may disrupt the text version, ultimately causing email delivery issues. In my case these are the items that broke the text version of the email:

  • The double quotes – this did not even render it just stopped rendering at the double quotes, i guess it has thrown some error that was not visible to me.
/*
this script 
%%=redirectto(Concat(@ProductUrl1, @qpp1,"&"))=%%
rendered in text version as
*/
%%=redirectto(Concat(@ProductUrl1, @qpp1,
                     
/*
For delivery in delivery logs visible on support side they were able to see following error
ExactTarget.InvalidFunctionException: The function call does not end with the required close parenthesis [)]
Function Call: redirectto(Concat(@ProductUrl1, @qpp1,,?
*/     
  • indexof function – When I have removed the double quotes it worked as expected and even email has been delivered. So I wondered this was it? this is the reason why also my indexof did not work? I gave it a second chance and tried to render text version. It looked good as it did not break anything but it brought other attributes from the href tag, which for some reason caused proof email was not sent. The problem is using indexof with greater than sign > use !=0 instead. I am waiting for support to get back to me with root cause.
https://martechnotes.com?a=b&c=d" class="..." title"...">

Oh hi there 👋
I have a FREE e-book for you.

Sign up now to get an in-depth analysis of Adobe and Salesforce Marketing Clouds!

We don’t spam! Read our privacy policy for more info.

Share With Others

Leave a Comment

Your email address will not be published. Required fields are marked *

MarTech consultant

Marcel Szimonisz

Marcel Szimonisz

I specialize in solving problems, automating processes, and driving innovation through major marketing automation platforms.

Buy me a coffee