What is AMPscript?

AMPscript is a Salesforce proprietary scripting language that interacts with Marketing Cloud emails, landing pages, SMS and MMS messages and push notifications. By learning the AMPscript language, you can do any of the following:

Can add personalized, unique content for each subscriber.
• Example Subject Line: Hello, First Name!

Display content based on certain conditions.
• Example Subject Line #1: Hello, First Name!
• Example Subject Line #2: Hello, Valued Customer!

Format Date Values
• Example Date: Date might provide a date as “MM/DD/YYYY” but we want it to show as “Month Day, Year” instead.


AMPscript Syntax

As mentioned, AMPscript is a scripting language, and when you learn any new language, you first have to master how it works. AMPscript uses the following langauge elements.

• Constants
• Attributes and Data Extension Values
• Variables (or Keywords)


AMPscript Constants

Numeric Values
Numeric constant values consist of one or more digits. They are formatted as unquoted numerals. They can include 1 decimal point and an introductory minus sign for negative numbers. Commas, are not permitted.

String Values
A string is a set of one or more letters, numbers, spaces or special characters. These constant values must be surrounded (delimited) by double or single quotes. They can also include the same type of delimiting quote inside by doubling it.

Boolean Values
Boolean constant values must use the words true or false. They are not surrounded by quotes. They are also NOT case sensitive.

NULL Values
A NULL value represents the absence of a value. The use of a NULL value is just a pointer, which is pointing to nowhere in memory.


Attributes & Data Extension Values

Attributes and data extension values refer to any content held inside a subscriber list or a data extension. If the name includes a space or special character, you must surround it with opening and closing brackets. Best practice to always include the opening and closing brackets when using attributes. This adds consistency when troubleshooting.

Example Use Case
Let’s say you’re building an email and the data extension you’re sending to has two fields called “Birthdate” and “FirstName”. The example below demonstrates how you can pull the values from those fields to use within your email.


Variables (or Keywords)

A variable is a storage location for information you want to reference later on. A variable includes two parts, an identifier and a value. The Identifier is a symbolic name you want to use. The Value is the information you want to store.

Declaring Variables
When you declare a variable, you are telling the system that the variable exists. By default, whenever you declare a variable that variable will be set to NULL.
• Example: VAR @FullName

Setting Variables
When you’re ready to set a variable you can assign values to it.
• Example: SET @FullName = “John Doe”


Gallery