What is AMPscript?

AMPscript is a proprietary scripting language used solely within Salesforce Marketing Cloud. It is used specifically in content such as emails, landing page (CloudPages), SMS/Push messages.

What can AMPscript do?

Using AMPscript within your content allows you to be able to:

  • Display subscriber data and relational data within your content
  • Update, insert, manipulate data within your data extensions
  • Make calculations and decisions (simple or complex) on content generation or at time of send
  • Build row sets from a delimited string or XML
  • Allow you to use advanced 1:1 messaging within your content
  • And more …

What does this all mean?

It means that using AMPscript is flexible enough to suit most/if not all of your content needs — BUT you are not required to know AMPscript for personalization or dynamic content. The user interface in Content Builder allows you some of that functionality, but knowing how to use AMPscript will let you unlock more features.


The basics below are common to most all programming and scripting languages and also applies to AMPscript.

Syntax: The syntax is the structure of the scripting language and how the code needs to be written to work properly.

Variables: A variable is used as a storage location which contains data used in your scripting

Functions: Functions are special commands to tell the system to perform an action


The syntax of AMPscript needs to be written in specific delimiters. AMPscript can be written in blocks of code or inline.

Blocks of AMPscript code are written within opening and closing: %%[ ]%%

AMPscript blocks can used for:

  • declaring and setting variables,
  • processing conditional logic
  • large amounts of data processing

AMPscript used inline are written with opening and closing: %%= =%%

Inline AMPScript can be used for:

  • outputting variables or function responses
  • allows to easily embed into HTML


Variables are used to store data within your AMPscript block or inline AMPscript. Imagine them as containers that store data that you define. AMPscript variables all begin with the @ symbol and are defined using SET. Variables need to be unique names or else the data stored in them can be overwritten.


set @myvar = “My Variable”


Variables can be declared using VAR but it is not required. Multiple variables can be separated by comma.


var @myvar, @myvar2
set @myvar = “My Variable”
set @myvar2 = “My Variable 2”


Variables can contain numbers, letters, dash (-), or underscore (_), but must be begin with a letter.


set @myvar = “My Variable”
set @my-var = “My Variable”
set @my-var2 = “My Variable”
set @my_var = “My Variable”


Variables are all case insensitive. SET is also case insensitive.


set @MYVAR = “My Variable”
set @MyVar1 = “My Variable 1”
SET @myVAR2 = “My Variable 2”


Comments can be made within AMPscript using: /* */


/* This is a comment about My Variable */
set @MyVar = “My Variable ”



AMPscript is procedural and will be processed from TOP down. As mentioned earlier, if the variable is not unique, the data stored within them can be overwritten. In the example below, since AMPscript is processed from top down, the value for the variable @myVar will be the last one processed.


set @myVar = “This will be processed first”
set @myVar2 = “This will be processed next”
set @myVar3 = “This will be processed third”
set @myVar = “This will be processed last”




AMPscript functions are actions that tell the system what to do. There are hundreds of functions with very specific use cases broken out by categories below:

Ready to move on? More on Populating Dynamic Fields within your email with AMPscript

Leave a Reply

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