AMPscript guide syntax examples and what changed in Marketing Cloud Next
Salesforce implementation

AMPscript guide: syntax, examples and what changed in Marketing Cloud Next

Hyphenx Team
By Hyphenx Team
November 30, 2026

A personalization string gets you “Hi Sarah.” AMPscript gets you Sarah’s nearest store, her last order, a price in her currency and a different hero image because she’s a loyalty member.

This guide covers the syntax you’ll use every day, 8 copy-ready examples, how to debug, and what changed now that AMPscript also runs in Marketing Cloud Next.

What AMPscript is

AMPscript is Salesforce Marketing Cloud’s scripting language for personalizing content at send time. Salesforce’s AMPscript Function Reference describes it as a language for Marketing Cloud Engagement and Marketing Cloud Next that connects your customer data with your marketing content.

In Marketing Cloud Engagement, you can use it in emails, SMS, CloudPages and landing pages. If you’re new to it, Trailhead’s AMPscript for Nondevelopers module is a gentle start.

Syntax basics

AMPscript has 3 ways to appear in content:

Form

Use

Example

 

Code block

Logic and variables, no output

%%[ SET @name = “Sarah” ]%%

Inline

Output a value where it sits

%%=v(@name)=%%

Personalization string

Output a field directly

%%FirstName%%

A few rules to remember:

  • Variables start with @ and are declared with VAR, then set with SET
  • Functions and keywords aren’t case-sensitive, but be consistent
  • Strings use single or double quotes
  • Comments go inside /* */ in a code block
  • Code runs top to bottom, so set variables before you output them

8 examples you can adapt

1. A safe first name with a fallback

%%[
VAR @first
SET @first = AttributeValue(“FirstName”)
IF Empty(@first) THEN
  SET @first = “there”
ENDIF
]%%
Hi %%=ProperCase(@first)=%%,

AttributeValue() returns an empty value instead of an error when the field isn’t in the sending audience, which makes it safer than a bare personalization string.

2. Look up a value from another data extension

%%[
VAR @store
SET @store = Lookup(“Stores”, “StoreName”, “StoreID”, AttributeValue(“PreferredStoreID”))
]%%
Your nearest store: %%=v(@store)=%%

3. Conditional content by tier

%%[
VAR @tier, @offer
SET @tier = AttributeValue(“LoyaltyTier”)
IF @tier == “Gold” THEN
  SET @offer = “20% off this weekend”
ELSEIF @tier == “Silver” THEN
  SET @offer = “10% off this weekend”
ELSE
  SET @offer = “Free delivery this weekend”
ENDIF
]%%
%%=v(@offer)=%%

4. Loop through recent orders

%%[
VAR @rows, @row, @i
SET @rows = LookupOrderedRows(“Orders”, 3, “OrderDate DESC”, “SubscriberKey”, _subscriberkey)
FOR @i = 1 TO RowCount(@rows) DO
  SET @row = Row(@rows, @i)
]%%
<p>%%=Field(@row, “ProductName”)=%% on %%=FormatDate(Field(@row, “OrderDate”), “d MMM yyyy”)=%%</p>
%%[ NEXT @i ]%%

5. Format a price for the reader’s locale

%%=FormatCurrency(AttributeValue(“CartTotal”), “en-GB”)=%%

6. Build a tracked, personalized link

<a href=”%%=RedirectTo(Concat(‘https://example.com/account?id=’, _subscriberkey))=%%”>View your account</a>

Wrap personalized URLs in RedirectTo() so Marketing Cloud can track the click.

7. Pick an image by category affinity

%%[
VAR @cat
SET @cat = Lowercase(AttributeValue(“TopCategory”))
IF Empty(@cat) THEN SET @cat = “default” ENDIF
]%%
<img src=”https://example.com/heroes/%%=v(@cat)=%%.jpg” alt=”Picked for you”>

8. Stop a send for bad data

%%[
IF Empty(AttributeValue(“Email”)) OR Empty(AttributeValue(“Country”)) THEN
  RaiseError(“Missing email or country”, true)
ENDIF
]%%

RaiseError() with true skips that subscriber and continues the send, which is safer than sending broken content.

AMPscript in Marketing Cloud Next

Marketing Cloud Next (the Growth and Advanced editions on the core platform) originally used Handlebars for personalization. Salesforce added AMPscript in the Summer ’26 release, and the function docs now show separate support columns for Engagement and Next.

Support is partial, and some functions behave differently. The Lookup() reference shows the pattern:

  • It became available in Marketing Cloud Next in Summer ’26 (API version 67.0)
  • In Engagement, you name a data extension, while in Next you give the API name of a marketing object
  • In Next, an odd number of search arguments returns an error

Functions tied to Engagement-only features, such as CloudPages, social forwarding and data extension writes, aren’t available in Next. Check each function’s support column before you reuse old code.

AMPscript or Handlebars?

In Marketing Cloud Next, you have both. Salesforce’s Handlebars for Marketing Cloud Next guide describes built-in helpers for working across data sources, filtering, sorting and applying logic.

Situation

Better choice

 

New templates built only for Marketing Cloud Next

Handlebars

Marketers editing templates without a developer

Handlebars, plus content variations and merge fields

Porting existing Engagement emails

AMPscript, where the functions are supported

Complex logic in Engagement (CloudPages, data writes, API calls)

AMPscript in Engagement

If you’re planning a move from Engagement to Next, inventory your AMPscript first. Code that writes to data extensions, calls APIs or runs on CloudPages usually needs redesigning, not copying. Our guide to Marketing Cloud Growth vs Advanced covers the wider edition choice.

Debugging checklist

Debbuging checklist

  1. Preview with real subscribers. Use subscriber preview with records that have empty, short and unusual values.
  2. Output variables temporarily. Print %%=v(@var)=%% next to the logic while testing, then remove it.
  3. Check field names. A typo in a data extension or column name is the most common failure.
  4. Check data types. Dates stored as text break FormatDate() and comparisons.
  5. Guard every lookup. Wrap outputs in IF NOT Empty() so a missing row doesn’t leave a blank sentence.
  6. Send a test to a seed list. Some functions only behave correctly at send time, not in preview.
  7. Keep shared logic in a content block. Reuse it with ContentBlockByKey() rather than copying it into every email.

Performance and maintenance

Each lookup runs for each subscriber. A large send with 10 lookups per email does a lot of work, so pull what you need into the sendable data extension with a SQL query activity when you can.

Comment your code, name variables clearly, and keep a library of tested snippets. The next person to edit the email will thank you.

Where AMPscript fits in a program

AMPscript decides what each message says. Journey Builder decides who gets which message and when, and Marketing Cloud Personalization can decide content in real time at open.

All 3 depend on clean, connected data. In our prospecting tools case study, the first win came from getting enrichment data into 1 Salesforce record, which is exactly what reliable personalization needs.

Frequently asked questions

What is AMPscript used for?

AMPscript personalizes Marketing Cloud content at send time. It’s used to look up related data, show conditional content, format dates and prices, loop through records like recent orders, build tracked links and, in Engagement, power CloudPages and landing pages.

Does AMPscript work in Marketing Cloud Next?

Yes, since the Summer ’26 release, but only for a subset of functions. Salesforce’s function reference marks each function as supported or not in Engagement and in Next, and some, like Lookup(), work differently in Next.

Is AMPscript hard to learn?

The basics take a day or 2 for anyone comfortable with spreadsheets or simple code. Lookups, loops and debugging take longer. Trailhead’s AMPscript for Nondevelopers module is a good free starting point.

What’s the difference between AMPscript and SSJS?

AMPscript is built for personalizing content and is simpler for most email work. Server-side JavaScript (SSJS) runs in Marketing Cloud Engagement for heavier processing, API calls and automation scripts. Many teams use AMPscript in emails and SSJS in automations.

Get help with AMPscript and Marketing Cloud builds

HyphenX builds and maintains Marketing Cloud emails, Journey Builder programs and personalization, including AMPscript audits before a move to Marketing Cloud Next. Talk to our Salesforce Marketing Cloud services team, or hire a Marketing Cloud specialist for ongoing work.

Like what you see? Share with a friend.

Best CRM Software for Businesses: Why Companies Are Choosing Salesforce

Best CRM Software for Businesses: Why Companies Are Choosing Salesforce

Share with your community!

Agentic testing

What's trending

agentic-testing-poster

Most Related Blogs

Salesforce Consumer Goods Cloud_ what it does and when it fits
Uncategorized    02 December 2026

Salesforce Consumer Goods Cloud: what it does and when it fits

Consumer goods companies spend heavily to win at the shelf, through field reps, promotions and distributors. Yet much…

Read More...
Salesforce Life Sciences Cloud_ a 2026 guide for pharma and medtech
Salesforce Marketing Cloud    02 December 2026

Salesforce Life Sciences Cloud: a 2026 guide for pharma and medtech

For nearly 20 years, most pharma CRM ran on Salesforce through Veeva. That arrangement has ended, and many…

Read More...
Education Cloud for universities_ a better recruitment and admissions process (1)
Salesforce implementation    02 December 2026

Education Cloud for universities: a better recruitment and admissions process

Applicants compare your admissions process with the apps they use every day. If they have to email 3…

Read More...
What is Salesforce Education Cloud_ A 2026 guide for colleges and universities
Salesforce implementation    02 December 2026

What is Salesforce Education Cloud? A 2026 guide for colleges and universities

A typical university runs admissions in 1 system, advising in another, alumni giving in a third and student…

Read More...
Salesforce Nonprofit Cloud what it includes and how to implement it (1)
Salesforce Marketing Cloud    02 December 2026

Salesforce Nonprofit Cloud: what it includes and how to implement it

Most nonprofits come to Salesforce with donor data in 1 system, program data in spreadsheets and volunteer data…

Read More...
Nonprofit Cloud vs NPSP in 2026 should your nonprofit move, and when
Salesforce Marketing Cloud    02 December 2026

Nonprofit Cloud vs NPSP in 2026: should your nonprofit move, and when?

If you run the Nonprofit Success Pack, you’ve probably been told you must move to Nonprofit Cloud soon.…

Read More...

Most Related Blogs

Salesforce Consumer Goods Cloud_ what it does and when it fits
Uncategorized    02 December 2026

Salesforce Consumer Goods Cloud: what it does and when it fits

Consumer goods companies spend heavily to win at the shelf, through field reps, promotions and distributors. Yet much…

Read More...
Salesforce Life Sciences Cloud_ a 2026 guide for pharma and medtech
Salesforce Marketing Cloud    02 December 2026

Salesforce Life Sciences Cloud: a 2026 guide for pharma and medtech

For nearly 20 years, most pharma CRM ran on Salesforce through Veeva. That arrangement has ended, and many…

Read More...
Education Cloud for universities_ a better recruitment and admissions process (1)
Salesforce implementation    02 December 2026

Education Cloud for universities: a better recruitment and admissions process

Applicants compare your admissions process with the apps they use every day. If they have to email 3…

Read More...
What is Salesforce Education Cloud_ A 2026 guide for colleges and universities
Salesforce implementation    02 December 2026

What is Salesforce Education Cloud? A 2026 guide for colleges and universities

A typical university runs admissions in 1 system, advising in another, alumni giving in a third and student…

Read More...
Salesforce Nonprofit Cloud what it includes and how to implement it (1)
Salesforce Marketing Cloud    02 December 2026

Salesforce Nonprofit Cloud: what it includes and how to implement it

Most nonprofits come to Salesforce with donor data in 1 system, program data in spreadsheets and volunteer data…

Read More...
Nonprofit Cloud vs NPSP in 2026 should your nonprofit move, and when
Salesforce Marketing Cloud    02 December 2026

Nonprofit Cloud vs NPSP in 2026: should your nonprofit move, and when?

If you run the Nonprofit Success Pack, you’ve probably been told you must move to Nonprofit Cloud soon.…

Read More...

Get in Touch

Ready to launch your next project? Fill out the form below.