Marketing Automation, Salesforce Marketing Cloud, SFMC Rant

SFMC RANT: Inline AMPScript mystery

Salesforce Marketing Cloud Rant

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.

#AMPScript #email template
Marcel Szimonisz
Marcel Szimonisz
MarTech consultant As a marketing automation consultant, I specialize in solving problems, automating processes, and driving innovation in my clients' marketing platforms.

I hold certifications in Adobe Campaign v6 (3x certified) and Salesforce Marketing Cloud (5x certified).

Additionally, I serve as a community advisor for Adobe Campaign, offering expert insights and guidance.

In addition to my professional pursuits, I also enjoy exploring various programming languages, CMSs, and frameworks, further enhancing my technical expertise and staying at the forefront of industry advancements.
Take a look at our subscription offering in case you are looking for a Marketing Automation Consultant.

Leave a comment

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

Similar posts that you may find useful

Salesforce Marketing Cloud Tips
Journey builder, Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Refresh Delivery in Transactional Journey

1 minute read

The process might seem straightforward at first glance—simply refreshing the email delivery content in Salesforce Marketing Cloud should suffice to receive the updated email contents. However, there’s more to consider. Salesforce Marketing Cloud utilizes server-side caching, which may display outdated content. Understanding when the cache refreshes isn’t always clear. In scenarios where immediate changes are […]

Continue reading
Salesforce Marketing Cloud Tips
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

How to bulk change data extension fields

less than a minute read

As a Salesforce Marketing Cloud admin, you will learn that certain operations on data extensions are better handled via Email Studio, while others are more suited for Contact Builder. Today, I will explain when to use each method for adding or changing fields in a data extension. My preferred way to add or change fields […]

Continue reading
Adobe Campaign Classic tips
ACC Tips & Tricks, Adobe Campaign, Marketing Automation

How to aggregate data in technical workflow

1 minute read

Every now and then, you may receive a request to aggregate data within an Adobe Campaign Classic workflow. However, if you group by something other than the targeting dimension, you may encounter an error such as “‘w0.iid’ must appear in the GROUP BY clause or be used as an aggregate function. The reason behind Adobe […]

Continue reading
Adobe Campaign post
Adobe Campaign, Marketing Automation

Complete guide to data schemas in ACC

4 minutes read

I want to gather as much information I have and have it at one place for my future reference and for others to learn what can be possible with the custom schemas in the Adobe Campaign Classic – ACC If you work with adobe campaign for some time you might figured out that almost any […]

Continue reading
Salesforce Marketing Cloud Tips
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Not able to change data extension fields

less than a minute read

Sometimes, it can happen that you want to modify field properties, such as adding a primary key or changing the length of certain fields. However, even in these situations, you might encounter some unusual behaviors that you should be prepared for. To modify attributes, like changing from nullable to non-nullable or setting a different primary […]

Continue reading