AMPscript development

Personalised emails, SMS and CloudPages built with AMPscript that handles missing data gracefully and is readable by the next developer.

Overview of AMPscript development: dynamic email content, conditional blocks, data extension lookups, CloudPages, SMS and push personalisation and refactors

AMPscript is the scripting language that turns a Marketing Cloud Engagement email into a personalised one. It reads subscriber attributes, looks up rows in data extensions, builds conditional content and powers CloudPages such as preference centres. It is also unforgiving: a lookup that returns nothing, a date in an unexpected format or a null value in a function call can stop a send or render a broken message.

An experienced AMPscript developer writes code that expects imperfect data, stays readable and is tested against the real shapes of your data extensions.

What we build

  • Dynamic email content driven by profile attributes, order history or product recommendations stored in data extensions.
  • Conditional blocks for language, region, loyalty tier or lifecycle stage.
  • CloudPages for preference centres, unsubscribe flows and simple forms that write back to data extensions.
  • SMS and push message personalisation using the same data.
  • Refactors of existing scripts that have grown long, slow or fragile.

An example of defensive AMPscript

The snippet below greets a subscriber by first name with a fallback, then reads their most recent order from a sample data extension. It assumes a data extension called Orders_DE with fields SubscriberKey, OrderNumber and OrderDate. It is a teaching example, not drop-in production code.

ampscript
%%[
SET @firstName = AttributeValue("FirstName")
IF EMPTY(@firstName) THEN
  SET @firstName = "there"
ENDIF

SET @rows = LookupOrderedRows("Orders_DE", 1, "OrderDate DESC", "SubscriberKey", _subscriberkey)
IF RowCount(@rows) > 0 THEN
  SET @row = Row(@rows, 1)
  SET @orderNumber = Field(@row, "OrderNumber")
  SET @hasOrder = "true"
ELSE
  SET @hasOrder = "false"
ENDIF
]%%
Hi %%=v(@firstName)=%%,
%%[ IF @hasOrder == "true" THEN ]%%
Thanks for order %%=v(@orderNumber)=%%.
%%[ ELSE ]%%
Here is what is new this month.
%%[ ENDIF ]%%
Fallback for a missing first name and a guarded lookup of the latest order

Two habits matter here. AttributeValue returns an empty value instead of erroring when the attribute is missing, and the RowCount check prevents Row() being called on an empty rowset. For a fuller comparison of lookup functions, see AMPscript LookupRows vs LookupOrderedRows. When something breaks in a live send, How to Debug AMPscript Personalization Errors walks through the diagnosis, and the AMPscript Cheat Sheet keeps common functions to hand.

Problems we are often asked to fix

  • Sends that error for some subscribers. Usually a lookup or date function receiving an empty or badly formatted value. We reproduce it with the affected records and add guards.
  • Slow sends. Several lookups per subscriber across large data extensions add up. Moving the joins into SQL before the send often helps more than tuning the script.
  • Copy-and-paste sprawl. The same logic repeated in dozens of emails, each slightly different. We consolidate it into shared content blocks so a fix happens once.
  • Previews that look fine but live sends that do not. Preview subscribers often have complete data. Testing against deliberately incomplete records catches the difference.

How we deliver AMPscript work

  1. 01

    Understand the data

    We review the data extensions, field types and fill rates behind each personalisation rule, because most AMPscript bugs are really data problems.

  2. 02

    Write the logic in plain English

    Each rule is agreed as a short statement, such as show the loyalty block only when tier is Gold or Silver, before any code is written.

  3. 03

    Build with fallbacks

    Every lookup, date and attribute has a defined behaviour when the data is missing or unexpected.

  4. 04

    Test across data shapes

    We preview and test send against subscribers chosen to cover each branch, including empty and edge-case records.

  5. 05

    Document and hand over

    Code is commented, variables are named clearly and a short note explains where each data dependency comes from.

Deliverables

ItemDescription
Personalisation specificationThe agreed rules for each dynamic element, in plain language
AMPscript codeCommented code in content blocks or templates, organised for reuse
Test matrixThe test subscribers used and the result for each branch
Troubleshooting notesKnown edge cases and how to diagnose them

Questions we hear

Should we use AMPscript or Server-Side JavaScript?
AMPscript is usually the better fit for email and simple CloudPages; SSJS suits API calls and more complex processing. Our AMPscript vs SSJS guide covers the trade-offs.
Can you fix an email that fails to send because of a script error?
Yes. We reproduce the error with the affected subscriber data, fix the cause and add guards so similar records do not break future sends.
Do you build preference centres?
Yes, using CloudPages and AMPscript, with care over consent capture and how changes flow back to your CRM.
Is heavy AMPscript a performance problem?
It can be. Many lookups per subscriber slow down large sends, so we often move work into SQL that prepares data before the send.

Need an AMPscript developer?

Share the email or CloudPage you need built or fixed, and we will scope the work with you.

Discuss your project →

Next step: AMPscript Development

  1. We read it A practitioner reads your message and replies by email.
  2. Short call We confirm goals, constraints and what success looks like.
  3. Written scope You get a scope and estimate before any work starts.

Tell us what you are trying to fix.

Share your Salesforce setup, goals and constraints. A practitioner reads every message and replies with questions, first thoughts or an honest view of whether you need outside help at all.

Talk to a Salesforce Expert
Book a Consultation