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

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.
%%[
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 ]%%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
- 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.
- 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.
- 03
Build with fallbacks
Every lookup, date and attribute has a defined behaviour when the data is missing or unexpected.
- 04
Test across data shapes
We preview and test send against subscribers chosen to cover each branch, including empty and edge-case records.
- 05
Document and hand over
Code is commented, variables are named clearly and a short note explains where each data dependency comes from.
Deliverables
| Item | Description |
|---|---|
| Personalisation specification | The agreed rules for each dynamic element, in plain language |
| AMPscript code | Commented code in content blocks or templates, organised for reuse |
| Test matrix | The test subscribers used and the result for each branch |
| Troubleshooting notes | Known edge cases and how to diagnose them |
Workflow diagram
Explore how the pieces fit together. Select a step to read what happens there.
Select any step in the diagram, or use Step through, to see what happens at that point and why.
Text version: every step in order
- Issue reported Ops teamMissing or wrong email
A customer or colleague reports a missing email or wrong personalised content. Note the subscriber key, the email and the approximate send time.
Next: Query send log
- Query send log Send log DEBy key and JobID
Send logging writes a row per subscriber per send with JobID, ListID, BatchID and any custom fields you add. A SQL query or filter finds the row.
Next: Logged at send time?
- Logged at send time? Send log DE
A row means the platform attempted the send to that subscriber. No row means they were excluded before sending, so the check moves to status and exclusions.
Next: Yes: Compare values; No: Check status
- Check status Subscriber recordsUnsubscribed, held, suppressed
Check the All Subscribers status, bounce history in the _Bounce data view, exclusion scripts and suppression lists. Most missing-email cases end here.
Next: Cause found
- Cause found Subscriber recordsExpected, or rule corrected
Either the exclusion was correct and is explained to the requester, or a wrong rule is corrected for future sends.
End of the flow.
- Compare values Send log DELogged vs source
Custom send log fields capture AMPscript variables at send time. Comparing them with the source row shows whether the data or the code produced the wrong content.
Next: Wrong data or code?
- Wrong data or code? Send log DE
If the logged values match a wrong source record, the data is at fault. If the source was right but the output was wrong, the AMPscript logic is.
Next: Data: Fix source data; Code: Fix the AMPscript
- Fix source data Subscriber recordsThen check sync or import
Correct the record at its source, not only in the data extension, or the next sync or import will bring the wrong value back.
Next: Fix verified
- Fix the AMPscript Ops teamPreview and test sends
Correct the logic, then preview as the affected subscriber and send tests. Handling empty values explicitly stops the same failure for others.
Next: Fix verified
- Fix verified Ops teamResend only if appropriate
The fix is verified with a test send. Whether to resend depends on the message; a duplicate promotion can do more harm than the original error.
End of the flow.
Questions we hear
Should we use AMPscript or Server-Side JavaScript?
Can you fix an email that fails to send because of a script error?
Do you build preference centres?
Is heavy AMPscript a performance problem?
Need an AMPscript developer?
Share the email or CloudPage you need built or fixed, and we will scope the work with you.
Part of our Marketing Cloud work: Salesforce Marketing Cloud Consulting




