MARKETING CLOUD / AMPSCRIPT
AMPscript
Personalization, lookups, and the AMPscript idioms that survive a hand-off. Anchored to the kinds of email logic that ship every day.
Foundation · 2
Production note
MC AMPscript gotchas: what survives a hand-off
AMPscript looks like a simple template language. The reality at scale is three different variable syntaxes, three NULL checks that mean different things, a lookup API that fails silent, and a preview that doesn't render the same code path as the send. Ten gotchas anchored to the next person inheriting your email.
Decision framework
Marketing Cloud AMPscript: Style Guide
The opinionated rules Cleon applies to every AMPscript block we ship in Marketing Cloud — naming, formatting, commenting, patterns to prefer, anti-patterns to refuse — distilled from the gotchas and reference pages into a single discipline document. Mirrors the SQL and SSJS Style Guides.
Reference · 9
Reference
Basics — Marketing Cloud AMPscript fundamentals
Where AMPscript runs in Marketing Cloud, the three syntax forms (block, inline function, field interpolation), the function categories at a glance, and the decision tree for when to reach for AMPscript vs SSJS vs SQL.
Reference
String functions — Marketing Cloud AMPscript reference
The string operations available in AMPscript — every function with the inverted indexing (1-based, not 0-based), the replace-all-by-default behavior, and the small set of formatting helpers. Where it diverges from SSJS and SQL, plus the patterns Cleon ships.
Reference
Date functions — Marketing Cloud AMPscript reference
AMPscript's date surface — Now / DateAdd / DateDiff / DatePart / FormatDate / DateParse. The timezone trap (MC system clock is CST regardless of where the tenant is), the month-math instability, and the patterns that survive at scale.
Reference
Math functions — Marketing Cloud AMPscript reference
AMPscript's math surface — six functions, no operators, silent string-to-number coercion. Divide-by-zero behavior changes between tenants, money math has floating-point traps, and 'abc' becomes 0 without warning. The patterns that survive at scale.
Reference
Validation functions — Marketing Cloud AMPscript reference
AMPscript's validation surface — Empty / IsNull / IsEmailAddress / IsPhoneNumber / IsNumeric. Useful for render-time branching, dangerous as a substitute for upstream data quality. The patterns that survive at scale.
Reference
Data Extension functions — Marketing Cloud AMPscript reference
The DE read and write functions — Lookup, LookupRows, LookupOrderedRows, Row, Field, RowCount, InsertData, UpdateData, UpsertData, ClaimRow. The most safety-critical surface in the language: writes can fail silently, lookups can truncate at 2000, and a misaligned argument pair lands the wrong value in the wrong column.
Reference
Subscriber + Profile functions — Marketing Cloud AMPscript reference
AttributeValue, _subscriberKey, _emailaddress, _jobid, _messagecontext, and the rest of the context AMPscript inherits from the surrounding send. What each returns, when it's available, and the difference between Subscriber Attributes, DE columns, and local variables.
Reference
Cloud-write functions — Marketing Cloud AMPscript reference
AMPscript's bridge to Sales/Service Cloud — UpdateSingleSalesforceObject, CreateSalesforceObject, RetrieveSalesforceObjects. The highest-stakes surface in the language: writes are inline, return 1/0 without throwing, and can hit live production CRM records from a preview if you forget the messagecontext gate.
Reference
Encoding + Hashing functions — Marketing Cloud AMPscript reference
URLEncode, Base64Encode/Decode, HTMLEncode, the RedirectTo tracking wrapper, plus SHA1/SHA256/SHA512/MD5 hashes and symmetric encryption. Each function pairs with a production failure shape — wrong URL escaping breaks tracking links, missing HTMLEncode opens XSS in CloudPages, MD5 used as security instead of as a tracking key.
How-to · 3
How-to
Debugging render-time blanks
An email went out, recipients see 'Hello, ' with a blank where the first name should be. The Send shows Completed. AMPscript Lookup returned NULL without throwing. Five queries against the audience DE and any log DEs that find which of the three usual culprits the bug actually is.
How-to
Debugging preview-vs-send mismatch
The email rendered correctly in Email Studio's preview, went out, and the actual sent version is different. Six checkpoints that reproduce the divergence deterministically before the next send fires — context variables, _messagecontext gates, locale formatting, time-sensitive logic, Lookup data drift, and the only diagnostic that's truly conclusive: a real test send.
How-to
Debugging silent Cloud-write failures
An AMPscript Cloud-write reported success at render time. The email shipped. Days later, the sales team notices the Salesforce records the email was supposed to update are stale. UpdateSingleSalesforceObject returned 0 silently — and 0 means seven different things. Five queries against de_log_sf_writes that separate the seven.