SFMC RANT: Inline AMPScript mystery

Marketing Automation, Salesforce Marketing Cloud, SFMC Rant
3 minutes read

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"...">

Salesforce marketing cloud journey exit criteria and goals
Marketing Automation, Salesforce Marketing Cloud

How to use journey exit criteria and goals

3 minutes read

I might be really slow learning but I learned about this feature two years into working with salesforce marketing cloud, and I said to myself what a nice feature to have. Let me tell you what it is and give you some real life examples when to use it. Exit criteria and goals share a […]

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

Proof email was previewed but not received

2 minutes read

There are many possible issues, and I will try to list all those I have come across during my times when I wondered where my email is. Contact is unsubscribed If the contact you are trying to preview an email with is on one of the global unsubscribe lists, or has unsubscribed or bounced status […]

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

How to use MD5 in SQL and AMPScript

1 minute read

Message Digest 5 (MD5) is a hash function used for data integrity, but it is not suitable for security-critical applications. It has found use for various applications, one of which is to create an encrypted contact subscriber key. MD5 takes any string and produces a fixed-size (128-bit) hash value, that cannot be easily decrypted. To […]

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

WOW! SQL queries are case insensitive

1 minute read

I recently discovered that when querying data views, case sensitivity in column names doesn’t make a difference; it consistently picks up the column when named correctly. Let’s explore where else column case sensitivity doesn’t play a significant role. First let’s create a data extension with some columns so we can test following in Query studio, […]

Continue reading
SFMC consent management
Marketing Automation, Salesforce Marketing Cloud

Consent management in SFMC explained

6 minutes read

Even after a couple of years working with Salesforce Marketing Cloud, I am still somewhat lost on how the consent management works. I’ve decided to tackle all the uncertainties I’ve been avoiding since I first started. Let’s dive into this topic and resolve all doubts once and for all. As you might have noticed, there […]

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

How to add segments to proof subject

1 minute read

Issues arise when an email’s HTML contains personalization that includes multiple different variants, that is altering the appearance of the personalized email. Quality assurance (QA) of such proofs can become exceptionally challenging, particularly in cases where there are minor changes across variants or a substantial number of variants present. You can devide your variants by […]

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

Troubleshooting issues with Data Extensions

1 minute read

There are other aspects that I find rather unknown; while there is likely a rational explanation, the platform doesn’t provide straightforward answers. Here are some learnings of mine while working with data extensions: Importing in Contact Builder throws a validation error on the date field. The same file has been successfully imported via Email Studio.

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
Queries in SSJS and AMPScript
Marketing Automation, Salesforce Marketing Cloud

Query data extensions with SSJS and AMPScript

1 minute read

There’s another topic for which official documentation often lacks sufficient information, but it can be incredibly useful when needed. It’s important to note that in AMPScript, we use the data extension name to reference the table for any query. On the other hand, in SSJS, we utilize the data extension’s external key to reference the […]

Continue reading