Lookup(Answers) webinar wrap-up


Today I joined Salesforce MVPs Eliot Harper and Adam Spriggs who kicked off the new webinar series “Lookup(Answers)” moderated by Greg Gifford. This series gives the Marketing Cloud community the possibility to ask questions on a certain topic set for each episode, which are then covered in a one hour QA session. In this article, I’m summarizing the key takeaways so you don’t miss out even if you couldn’t attend.

How to get started with AMPscript

Make sure to get started by understanding the concepts behind AMPscript, the syntax, as well as some programming fundamentals (what is a variable, what is a function, how to use a loop, etc.). Most of this is already covered in the official documentation (specifically the syntax guide), but the AMPscript Guide written by Adam Spriggs and Eliot Harper provides even more beginner friendly information including real world scenarios.

Once you understand the basics, it is time to get going by looking for problems that you can solve using AMPscript. If you have found something suitable, just try to solve it using what you know and the resources you find online. If you are stuck and already checked the relevant resources and didn’t find a solution, you can describe your specific problem on Salesforce StackExchange and I’m sure one of the community members is going to help you out.

Further resources

Does it make sense for non-programmers to learn AMPscript?

AMPscript is here to stay, so even if you are starting out slow, in the future you will definitely benefit from acquiring some scripting skills. And the good thing is, you don’t have to be a developer to learn the basics of AMPscript. It is pretty easy to get started if you focus on basic use cases and language elements first (personalization, loops, etc.).

Even tough Salesforce hinted that many functionalities will be covered by point and click tools within Marketing Cloud, it isn’t possible to have a solution for all use cases using WYSIWYG tools, so AMPscript gives you a lot more control and it is highly recommended to learn it.

Favorite hack/trick

Using a filesharing service such as dropbox together with CloudPages can save you a lot of time, as updates in your code are immediately reflected without having to wait for the page to publish (which can take up to five minutes). You can even use a code repository like git instead of dropbox, which gives you the additional advantage of having version control for your code.

The CloudPage only includes the following line of code which loads your real code from the cloud service of your choice:


AMPscript order of execution

AMPscript is interpreted from top to bottom. However, for emails OMM interprets in the following order:

  1. Preheader (as part of HTML Body)
  2. HTML Body
  3. Text Body
  4. Subject Line

This makes it possible to set your subject line dynamically based on AMPscript in your message body.

Email Body

    VAR @subjectLine
    IF AttributeValue('Member Status') == 'VIP' THEN
        SET @subjectLine = 'An exclusive offer for VIP members'
        SET @subjectLine = 'A special offer for our members'



Errorhandling and Debugging Best Practices

It is recommended to anticipate every possible error and check for those errors or invalid values (defensive coding). This gives you the possibility to react by altering content if feasible or preventing the send from happening using the RaiseError-function.

For debugging purposes it is often helpful to add debug output that is only displayed if a debug flag/variable is set accordingly. The following example shows two possibilities, one that is pure AMPscript and one that mixes AMPscript with HTML which gives you a bit more flexibility and can also be used for errorhandling.

    var @debug, @firstName

    SET @debug = 1
    SET @firstName = AttributeValue("firstName")
    SET @firstName = ProperCase(@firstName)

    IF @debug == 1 THEN
        Output(Concat("<br>firstName: ", @firstName))

%%[ IF @debug == 1 THEN ]%%
<br>firstName: %%=v(@firstName)=%%
%%[ ENDIF ]%%

API Usage Best Practices in AMPscript

The standard AMPscript functions let you interact with Marketing Cloud’s SOAP API. However, these functions are not available in Send Context, so they are exclusively for use on CloudPages. Most people use these functions on one-click unsubscribe pages to trigger the LogUnsubEvent for example.

So AMPscript API functions are rarely used, but are a gateway to learning SOAP objects which are fundamental to understand what is possible in Marketing Cloud.

FYI: Eliot doesn’t do API interactions using AMPscript anymore, and instead uses WSProxy in SSJS to interact with the API.

Parsing JSON

AMPscript isn’t capable of handling JSON natively, but for some use cases regular expressions might be useful. However, if you need to use JSON structures, you should have a look at Server-Side JavaScript or Guide Template Langauge (GTL) depending on your use case. GTL can also be combined with AMPscript if necessary.

FYI: Adam suggests using SSJS instead, as he doesn’t think GTL will have a bright future in Marketing Cloud.

Lookups in Mails

If you have more than two Lookups to the same data extension in an email, you should consider utilizing LookupRows, LookupOrderedRows, etc. instead. Another best practice is preparing your data beforehand by writing the desired data to your send’s data extension via SQL, etc. to reduce the need for extensive lookups and processing via AMPscript.


It is best practice to wrap accessing subscriber related data using AttributeValue, as it returns either the value or an empty string, but doesn’t break your email if an attribute or column is missing for example.

CloudPages - AMPscript vs. SSJS

90% of CloudPages developed by Adam and Eliot are written in SSJS, as it is more flexible due to the possibility to use arrays and JSON natively for example. However, they both combine it with AMPscript in many use cases.

I totally agree with them and also just perform the tasks that aren’t possible or as straightforward in SSJS using AMPscript (for example retrieving/updating Salesforce Core records).

Further tips/information

This section covers tips and information that came up during the webinar, which isn’t directly related to AMPscript

Use the LogUnsubEvent!

Use it, as it covers some very useful functionality:

  • Unsubscribes the subscriber from All Subscribers or the desired list
  • Tracks an unsubscribe, so it is counted towards the correct send (and is available in tracking)
  • Checks “HasOptedOutOfEmail” flag in Salesforce Core if Marketing Cloud Connect is used
  • Lets you track an unsubscribe reason

Difference between Salesforce Data Extension and regular data extension

Salesforce Data Extensions behave the same in regards to AMPscript, so just the location is different. But using the data extensions in these folders is important in order to have Individual Email Results written to your connected Salesforce Core Org.

Lookup(Answers) webinar series

As already mentioned up front, this was the start of a webinar series dedicated to Marketing Cloud QA sessions, that kicked off with AMPscript as a first topic. So if you have any questions or just want to learn more about Marketing Cloud, make sure to sign up for the next episode of “Lookup(Answers)”.

If you have any questions regarding this webinar series in general, get in touch with Guilda Hilaire from Salesforce, who is always happy to help.