Skip to main content
Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.

Write Your Best Scripts with Programmatic Languages

Learning Objectives

After completing this unit, you'll be able to:

  • Use AMPscript, SSJS, and GTL at the most appropriate times.
  • Troubleshoot your programmatic languages.
  • Preserve View As A Web Page functionality for your messages.

Now that you’ve been properly introduced to the different Marketing Cloud Engagement programmatic languages, you can decide when to use these tools in your development process. Each language offers different benefits and can be more useful than the others in certain situations. But first, let’s look at some best practices for all the languages.

All Languages

No matter which language you use, Marketing Cloud Engagement offers send preview and markup validation in the app. Always test your scripts before placing them in a send to make sure that everything works. Marketing Cloud Engagement prevents content with errors from sending, but you also want to make sure that you're getting the results you want. Perform test sends before deploying any new message or activity.

The NotSent tracking extract provides information on email messages that didn't send, including detailed reasons for the causes that prevented the send. Use this information to better refine your sends.

Because some AMPscript and SSJS functions allow access to API functions, make sure that the user you test and generate your scripts with has the appropriate permissions to interact with the API before you continue. Contact your Marketing Cloud Engagement admin for help if needed.

Email messages offer a View as a Web Page option to show HTML content outside of an email client. Because programmatic languages allow dynamic content, though, a forwarded email or the same email message sent more than once can reference an earlier version of the email message and not reflect any changes you may have made. The web page also loads information dynamically, instead of showing a snapshot of the actual sent message. To avoid this situation, reference the BatchID of the send in your scripts to ensure the correct email message is displayed as a web page.

AMPscript

AMPscript offers the most access to Marketing Cloud Engagement functionality, especially email messages. It also offers a tight integration with the SOAP API. If you take the time to learn the intricacies of this language, you can accomplish a great deal of Marketing Cloud Engagement functionality. AMPscript works best with subscriber list and data extensions stored in Marketing Cloud Engagement.

A large part of AMPscript involves pulling information from data extensions, and that usually involves Lookup() or LookupRows() functions. When you’re using these functions, remember that each call to a data extension requires time and processing power, so get as much data as possible with each call. Instead of several Lookup() calls for multiple fields, use a single LookupRows() request to pull back entire records and get data from there.

AMPscript also requires some functionality to be enabled before you can use it within an account. For example, you can't use AttachFile() unless that feature is activated for your account. Even then, be careful when adding attachments to messages. Some spam filters may block messages with attachments, and a send with a large attachment can cost time and processing power. Review the documentation for a function and make sure your account can use it before including it in your activities.

SSJS

SSJS offers the familiarity of JavaScript with the functionality of most AMPscript functions. That functionality includes integration with the SOAP API. If the data you want to use in Marketing Cloud Engagement requires arrays or comes in JSON form, SSJS gives you easy access to that data.

Remember to use Core functions only with landing pages and apps for the best performance. Platform functions can better handle messages and other send-time activities.

SSJS also offers enhanced error handling functionality, such as try catch blocks. If you require these checks, implement SSJS in your messages.

GTL

To create lightweight templates for different types of messages, GTL has you covered. The similarity to Handlebars.js and Moustache.js libraries make the language familiar, and you can create personalized templates with just a few tags. GTL can also access JSON data stored in data extensions or provided at send time. GTL can work with AMPscript or SSJS, or you can use it on its own.

Wrapping It All Up

Your messages, landing pages, and other assets all benefit from expanded functionality and personalization. Use these languages to give your subscribers exactly what they need. You can also help yourself by automating a lot of common tasks that can otherwise take a lot of time and effort.

Finally, the Salesforce StackExchange is a great source of help when troubleshooting your scripts. Search for previous issues and post if you think you’ve found something different than anybody has discovered before. Chances are that somebody has even been down that trail before!

Resources

Teilen Sie Ihr Trailhead-Feedback über die Salesforce-Hilfe.

Wir würden uns sehr freuen, von Ihren Erfahrungen mit Trailhead zu hören: Sie können jetzt jederzeit über die Salesforce-Hilfe auf das neue Feedback-Formular zugreifen.

Weitere Infos Weiter zu "Feedback teilen"