AMPscript Guide
AMPscript Guide
AMPscript Guide
1
AMPscript Guide
AMPscript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
What Is AMPscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Why Use AMPscript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Relational Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Display Metadata about the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Provide Control Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Format Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Impression Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2
AMPscript Guide
Using Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Using AMPscript Language Elements with Enterprise Awareness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Using Data Modification Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Send Time Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Landing Page Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Using Execution Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Using Dynamic Link Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Date and Time Formatting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3
AMPscript Guide
Notes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
RetrieveSalesforceObjects(S1,S2,S3a,S3b,S3c,...Sna,Snb,Snc). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
LongSFID(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Argument. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
UpdateSingleSalesforceObject(S1,S2,S3a,S3b,...Sna,Snb). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Sending an Email Message to a Salesforce Object via AMPscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4
AMPscript Guide
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5
AMPscript Guide
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
TransformXML(S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
TreatAsContent(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
TreatAsContentArea(S1,S2,S3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
WAT and WATP (S1, S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
6
AMPscript Guide
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
LookupRows(S1, S2, S3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
LookupRowsCS(S1, S2, S3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
UpdateData(S1, N1, S2, S3, S4, S5) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
UpdateDE(S1, N1, S2, S3, S4, S5). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
UpsertData(S1, N1, S2, S3, S4, S5) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
UpsertDE(S1, N1, S2, S3, S4, S5) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
7
AMPscript Guide
8
AMPscript Guide
LiveContentMicrositeURL(S1, S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
QueryParameter(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
URL Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
AMPscript Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Redirect(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
RequestParameter(P1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
9
AMPscript Guide
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Concat(S1,S2,...Sn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
DecryptSymmetric(S1, S2, S3, S4, S5, S6, S7, S8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Divide(N1, N2). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Domain(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
EncryptSymmetric(S1, S2, S3, S4, S5, S6, S7, S8, S9, S10). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Empty (V1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Format (V1, S1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Example 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Example 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
GUID() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
IIf(E1,S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
IndexOf(V1, S1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
IsEmailAddress(S1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
IsNull(P1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
IsPhoneNumber(P1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Argument. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Length(V1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Lowercase(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
10
AMPscript Guide
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
MD5(S1,S2). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Mod(N1, N2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Multiply(N1, N2). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Output(C1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
OutputLine(C1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
ProperCase(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Random(I1, I2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
RegExMatch(S1,S2,S3,S4...Sn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Replace(V1, S1, S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
ReplaceList(S1, S2, S3,...Sn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
SHA256(S1,S2). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
SHA512(S1,S2). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
StringToDate(S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
StringToHex(S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Substring(S1, I1, I2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
11
AMPscript Guide
Subtract(N1, N2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Trim(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Uppercase (S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
V(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
12
AMPscript Guide
Upcoming Rock Shows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
13
AMPscript Guide
xtlongdate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
xtmonth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
xtmonthnumeric. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
xtshortdate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
xtyear. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
view_email_url. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
14
AMPscript Guide
AMPscript
This document contains conceptual, scenario, and reference information about AMPscript and functions.
This document is intended for use by application users who are creating message content with AMPscript.
Knowledge of scripting languages may be required to use this functionality.
What Is AMPscript
AMPscript is a scripting language that you can embed within HTML emails, text emails, landing pages, and
SMS messages.
The system processes the script at the point where you include it in the message to render content on a
subscriber-by-subscriber basis. The ExactTarget application handles all AMPscript calls at the end of the
email send, so realize that you must write your calls appropriately. See How AMPscript Calls Are Processed
for more information and sample code.
AMPscript can also interact with your data extensions. You can use AMPscript to include information from
your data extensions in your messages and to update data extensions with information from your landing
pages.
More information on AMPscript, including several instructional guides, can be found at the links below:
AMPscript 15
AMPscript Guide
Relational Data
You can use a function to look up relational data. For example, you can use a function to find an airport
name from an airport code associated with a subscriber.
You can use a function to return multiple records that relate to a subscriber, such as all the rates for flights
from the subscriber’s home city to a city the subscriber recently searched for.
A function can limit the number of records returned from the relational data. For example, you can ask to
see only the top three fares for flights from a subscriber’s home city to another city.
A function can store subscriber values as variables on which your program can perform operations.
Format Values
You can use a function to format text, numeric, date, and time values.
Impression Tracking
Impression tracking lets you define a region within your email to measure the performance of that region.
The region you define can contain dynamic content or you define it to contain links and images in your
static content.
Using AMPscript, you can identify regions within your emails for impression tracking. You use the
following functions to enable this solution:
• BEGINIMPRESSIONREGION()
• ENDIMPRESSIONREGION()
• CONTENTAREA()
• CONTENTAREABYNAME()
The names of impression regions in all of the above functions must be fixed (constant strings or numbers).
Impression region names are case insensitive and are stored at their first occurrence. There is no limit to
the number of unique impression regions you can define.
If an impression region is not explicitly closed, it will be implicitly closed at the end of the message being
built, so an impression region opened in the HTML version of an email will not remain open when the text
version of the message is built.
Impression regions can be nested. If multiple regions are opened without being closed, all remain open and
the final one opened remains the active one returned for resolving the related substitutions. If one
EndImpressionRegion() call is issued, the second-to-last region will becomes the active region as so on.
Issuing EndImpressionRegion(true) closes all open regions.
Impression regions are tracked by Job and can be used in both HTML and text content.
%%[script]%%
%%=LOWERCASE(Name)=%%
%%=UPSERTDE("ent.CustomObject4",2,"Region","None","Product",_SubscriberKey,"Avail
"Price",100.77,"Inventory",0,"ExpireDate",NOW(),"Url",CONCAT(SubscriberID,"
Upsert"))=%%
The inline AMPscript example below demonstrates how to include multiple AMPscript references inside a
single set of delimiters:
<a
href="%%=RedirectTo(TreatAsContent(Concat(view_email_url,"&ep=20110902&oeid=20110
Function output can also be referenced in script and function calls. In the case of functions, this is
implemented through nested function calls. For example:
%%=LOWERCASE(SUBSTRING(Name, 1, 5))=%%
Minimum Syntax
This sample illustrates the minimum syntax necessary to declare an AMPscript block.
Full Syntax
This sample illustrates the complete syntax used to declare an AMPscript block.
The AMPscript block must be closed in the same syntax that opens it. For example, if you open a block
using <script>, you must close it with </script> and not ]%%.
Delimiter Comparison
The table below demonstrates the similarities between standard AMPscript delimiters and server-side
delimiters.
<script runat=server
%%[
language=ampscript>
<script runat=server
language=ampscript
%%[[type=post;name=blockname]
executioncontexttype="Post"
executioncontextname=blockname>
]%% </script>
<script runat=server
%%[]%%
language=ampscript />
You can use ExactTarget function calls inside AMPscript blocks or outside of script blocks: anywhere a
traditional substitution string is valid. Function calls outside of AMPscript blocks must be introduced by
the opening delimiter %%= and terminated by the closing delimiter =%%. Function calls within AMPscript
should not include these delimiters. These function calls will be executed even if they are not part of a
scripting statement, such as SET or IF.
%%=LOWERCASE(Name)=%%
Constant Value
LOWERCASE("Mary Smith")
Attribute Value
LOWERCASE(Name)
Variable Value
LOWERCASE(@Name)
• Constants
• Attributes and Data Extensions
• Keywords
Constants
AMPscript can include numeric constants and string constants.
Numeric constant values consist of an unquoted set of numerals and can also include one decimal point and
an introductory minus sign to indicate negative values. Numeric constant values cannot contain commas.
Here are some examples:
123
-123
123.456
String (or text) constant values must be quoted in double or single quotes. String constants can escape the
delimiting quote character if they appear within the text by doubling it. Alternative quote characters, such
as smart quotes, are not recognized.
"123.456"
Boolean constant values must be true or false and are case insensitive. Here are some examples:
true
false
TRUE
False
EmailAdr
[Total-Expense]
You can define additional email attributes within the email and use them in substitutions or as parameters
in AMPscript function calls. ExactTarget must enable the use of additional email attributes for you
account. Contact your ExactTarget representative with any questions about this functionality.
Keywords
Variables can be declared, initialized, and modified within a script. Variables then can be referenced by
script statements and functions.
A variable declaration consists of the keyword VAR followed by one or more comma-delimited variable
names. Variable names must begin with the @ symbol and be followed by at least one other letter, number,
or underscore. Spaces and commas are not allowed in variable names. For example:
@Name
@C1
A variable assignment consists of the keyword SET followed by the variable name, equal sign, and value.
Declaring a variable with the VAR keyword adds an entry to the Variables Dictionary with the variable
name as the key and NULL as the value. If an entry for that name already exists, the value of the variable is
set to NULL. If the variable is being used to control a FOR loop, an attempt to declare it will result in a
validation or runtime error.
%%[VAR @Count]%%
== Is equal to
!= Is not equal to
Using IF Syntax
Statements
Use the elseif statement to perform conditional processing. Multiple elseif statements can
elseif
appear within an if block.
Use the else statement to perform conditional processing. Exactly one else statement can
else
appear within an if block.
Use the endif statement to end an if block. Exactly one endif statement must appear at the end
endif
of an if block.
The ELSEIF statement is optional and can be repeated as desired to evaluate additional conditions.
The ELSE statement is optional and can appear only once after the IF and all ELSEIF statements and before
the ENDIF to define default behavior if none of the preceding conditions evaluate True.
Multiple conditions can be used for an IF or ELSEIF statement. These must be joined by the AND or OR
keywords and can be grouped by parentheses to control the order of evaluation. The NOT keyword can be
used to reverse the evaluation:
Expressions can include any of the input types, including constants, variables, attributes/data extension
values, or function calls.
If the comparison operator and second expression are not included, an equal operator is assumed with a
comparison value of True.
The following example demonstrates how to include a variable if a value is present and leave that variable
out if no value is present:
The @Variable is a variable that will be locked from modification within the process loop.
The start and end index expressions can be any one of the four types of input that evaluates to an
integer—a numeric constant, an attribute or data extension value, a variable, or a function call—for
example, LookupRows().
The TO or DOWNTO keywords determine whether the value of the variable is increased or decreased by
one (1) with each iteration of the FOR loop. The variable value will be set or incremented by one (1) at the
end of each iteration of the loop. The end index expression will be compared to the new value of the
counter variable. If the value has not yet reached the end value or is not yet equal to the end value, the
loop will be continued.
The NEXT statement closes the FOR loop and can optionally be followed by the variable name that is
controlling the loop.
%%[
VAR @Count, @Count2
SET @Count = 0
SET @Count2 = 100
]%%
@Name
@C1
%%[Output(Now())]%%
The system prints the current date and time. The OutputLine keyword would return the same information
with a CRLF appended at the end.
The system prints "Example Text," as that text is the value of the variable @text.
Note that the code in the example below DOES NOT WORK:
Again, the code example above does not work because Output does not support the passing of direct
literals.
System prints "Exampl", as the Substring() function shown returns the first 6 characters in the text
starting with the first character, and it appends a CRLF at the end of the results.
Using Comments
AMPscript may contain comments—or non-executed notes—that allow you, as the author, to document
your code. You must open comments with the /* sequence and close comments with the */ sequence.
Comments may span multiple lines.
LookupRows()
Lookup()
LookupOrderedRows()
You can use the ENT. prefix with these functions to indicate to the system that the data extension being
operated on exists at the parent Enterprise level and not at the child level.
In the following example, the system looks up data from the MERCHANT data extension stored at the
Enterprise Administrator level:
%%[
Var @rows
Set @rows = LookupRows("Ent.Merchants","TRAVELWEB_MERCHANT_ID",200043800)
]%%<br>
%%=Field(Row(@rows,1),"merchant_name")=%%<br><br>
The key or filter fields for update and upsert calls are distinguished from the columns being set by the
second parameter for these calls. This parameter must have a value of 1 or more to indicate how many of
the following column name and column value pairs make up the key for finding the row to be updated.
The remaining name and value pairs specify the columns to be updated and the new values.
%%=UPDATEDE("DE_To_Update",1,"Filter Column","Filter
Value","Column","Value")=%%
The calls are executed only when they appear in the preferred email type of the subscriber. Therefore, if a
multi-part message is being built for a subscriber with an HTML email preference, the functions in the text
email body will not be executed even though it is built. In the same way, if a subscriber has a text email
preference, only the functions in the text version of the email will be processed.
A _SourceDE substitution string is provided to reference the source data extension for a send so that the
name does not have to be hard-coded.
Example
%%=INSERTDE("CustomObject4","Region","None","Product",_SubscriberKey,"Price",99.7
"Inventory", 88,
"ExpireDate",NOW(),"Available",1,"Inventory",77,"Locale",
LOOKUP("CustomObject3",
"Custom Object Value"
,"Region",Region),"_FromName","Bob",<"_FromEmail",LOOKUP("CustomObject2","EmailAd
"Region1",Region))=%%
%%=UPDATEDE("CustomObject4",1,"Region","None","Available",0,"Price",100.77,"Inven
"ExpireDate",NOW())=%%
%%=UPDATEDE(_SourceDE,1,"_CustomObjectKey",_CustomObjectKey,"Total &
Credit - Cost",_CustomObjectKey,"SubscriberID",SubscriberID)=%%
%%=UPSERTDE("ent.CustomObject4",2,"Region","None","Product",_SubscriberKey,"Avail
"Price",100.77,"Inventory",0,"ExpireDate",NOW(),"Url",CONCAT(SubscriberID,"
Upsert"))=%% %%=DELETEDE("CustomObject4","Region","None")=%%
• The functions are executed in real time as they appear in the landing page content.
• The functions return an integer specifying the number of rows affected by the requested
execution. For upsert operations, if the initial update affects no rows, an insert is performed and
the number of row affected by the last operation is returned.
• These functions generate an error if they appear in content that is not being built for landing
pages.
If the INSERTDE, UPDATEDE, UPSERTDE, or DELETEDE counterparts appear in landing page content, they
will be executed in the same manner, except they will not return the number of rows affected. They will
not be executed in a single batch in this context.
Example
%%=INSERTDATA("CustomObject4","Region","None","Product",_SubscriberKey,"Price",99
"Inventory", 88,
"ExpireDate",NOW(),"Available",1,"Inventory",77,"Locale",LOOKUP("CustomObject3","
Object
Value","Region",Region),"_FromName","Bob","_FromEmail",LOOKUP("CustomObject2",
"EmailAddress","Region1",Region))=%%
%%=UPDATEDATA("CustomObject4",1,"Region","None","Available",0,"Price",100.77,"Inv
0,"ExpireDate",NOW())=%%
%%=UPSERTDATA("ent.CustomObject4",2,"Region","None","Product",_SubscriberKey,"Ava
0,"Price",100.77,"Inventory",0,
"ExpireDate",NOW(),"Url",CONCAT(SubscriberID," Upsert"))=%%
%%=DELETEDATA("CustomObject4","Region","None")=%%
Execution context is supported by type and name and represented by the global read-only variable
@@ExecCtx. The system processes Load and Post types, and it defaults to Load if no context is specified in
the call. Any content without a specific execution context will always be processed. The system honors
any context type, and it only processes script blocks in the active content with the specified name. For
example, the ExactTarget system processes only script blocks named SaveData if the caller specifies the
Post context type and the blocks are located in a section of code executed for the Post type.
The caller sets @@ExecCtx to a string value of Load or Post, indicating the current execution context, and
the value is case-insensitive. Use this variable to control the processing of content according to execution
context as shown in the example below:
You can also control processing of content using execution context names. When the caller specifies a
name, only script blocks with that name are executed. Callers can also specify a script type at the script
block level, with the script name and type set immediately after the script start delimiter. Use single or
double quotes for the string values. Names and types are case insensitive:
%%[[name=”nameStr”;type=”Load|Post]…]%%
In this example, the UpsertData command executes only if the caller’s
execution context is set to POST and the name UpdateDate is specified:
%%[[name=”UpdateDate”;type=”
Post]UpsertData(”MyDE”,”Col1”,Val1,”Col2”,Val2)]%%
Script blocks must be completed within the same script block section. For example, any IF or FOR
statements inside a script block must be completed by an ENDIF or NEXT within the same named script
block. If script blocks span two or more script block sections, the ExactTarget returns the following error
message:
You can also use execution context to determine whether to display most current content or the content
current as of when the email was sent. This document provides an example of how to use AMPscript to
contextually display send-time content, which requires enabling the send logging feature.
This example tracks the link specified above separately by each subscriber’s region included in the send.
For example:
West Region
North Region…
There is a configuration limit on the number of unique resolved link names, as defined by a link alias, that
can be tracked for each link with a dynamic link name. This limit is 100 names. If the number of unique
link names exceeds this limit, the excess links are tracked under the original unresolved link name.
Date
Year Month Hours Minutes Seconds AM/PM Offset
(Example:
(Example: (Example: (Example: (Example: (Example: (Example: (Example:
Monday,
2011) August) 8) :00) :05) PM) -6:00)
August 15)
yy = 11 MM = 08 dd = 15 hh = 08 mm = 00 ss = 05 tt = PM zz = -06
MMM = zzz =
yyy = 2011 ddd = Mon H=8 - - -
Aug -06:00
Date
Year Month Hours Minutes Seconds AM/PM Offset
(Example:
(Example: (Example: (Example: (Example: (Example: (Example: (Example:
Monday,
2011) August) 8) :00) :05) PM) -6:00)
August 15)
For example, the AMPscript below takes the results of the DateAdd() function (using the examples from the
table) and returns it in the specified format:
The example below takes the value of Now(), offsets it using the DateAdd() function, then returns that
value in the specified format:
The example below outputs the Birthday attribute of a subscriber in the format specified:
%%[Output(Format([Birthday],"dd/MM/yyyy"))]%%
AmpscriptSyntaxHighlighting.zip
• Add(N1,N2)
• AddMscrmListMember(S1,S2)
• AddObjectArrayItem(O1,S1,S2)
• Arguments
• Arguments
• AttachFile(S1,S2,S3,B1,S4,S5,N1)
• AttributeValue(S1)
• AuthenticatedEmployeeID()
• AuthenticatedEmployeeNotificationAddress()
• AuthenticatedEmployeeUserName()
• AuthenticatedEnterpriseID()
• AuthenticatedMemberID()
• AuthenticatedMemberName()
• BarCodeURL(S1,S2,N1,N2,S3)
• Base64Decode(S1,S2)
• Base64Encode(S1)
• BeginImpressionRegion(S1)
• BuildOptionList(S1,S2,S3)
• BuildRowSetFromString(S1,S2)
• BuildRowSetFromXML(S1,S2,B1)
• Char(S1,S2)
• ClaimRow(S1,S2,S3,S4,...Sn,Sn+1)
• ClaimRowValue(S1,S2,S3,S4,S5,S6,...Sn, Sn+1)
• Concat(S1,S2,...Sn)
• ContentArea(I1,S1,B1,S2,N1)
• ContentAreaByName(S1,S2,B1,S3,N1)
• CreateMscrmRecord(S1,S2,S3a,S3b)
• CreateObject(S1)
• CreateSalesforceObject(S1,I1,S2a,S2b,...Sna,Snb)
• DateAdd(D1, I1, S1)
• DateDiff(D1, D2, S1)
• DateParse(S1,B1)
• DatePart(D1, S1)
• DecryptSymmetric(S1, S2, S3, S4, S5, S6, S7, S8)
• DeleteData(S1, S2, S3)
• DeleteDE(S1, S2, S3)
• DescribeMscrmEntities()
• DescribeMscrmEntityAttributes(S1)
• Divide(N1, N2)
• Domain(S1)
• Empty (V1)
• EncryptSymmetric(S1, S2, S3, S4, S5, S6, S7, S8, S9, S10)
• EndImpressionRegion(B1)
• Enterprise and Enterprise 2.0 Accounts
• ExecuteFilter(S1,S2,S3...)
• ExecuteFilterOrderedRows(S1,N1,S2,S3,S4...)
• Field(S1,S2)
• Format (V1, S1)
• GetPortfolioItem(S1)
• GetPublishedSocialContent(S1)
• GetSocialPublishURL(N1,S1,S2,S3...Sn)
• GetSocialPublishURLByName(S1,S2,S3,S4,S5...Sn)
• GUID()
• HTTPGet(S1,B1,N1,S2)
• HTTPRequestHeader(S1)
• IIf(E1,S1,S2)
• Image(S1,S2)
• IndexOf(V1, S1)
• InsertData(S1, S2, S3)
• InsertDE(S1, S2, S3)
• InvokeCreate(O1,S1,N1,O2)
• InvokeDelete(O1,S1,N1,O2)
• InvokeExecute
• InvokePerform(O1,S1,S2)
• InvokeRetrieve(P1,P2,P3)
• InvokeUpdate(P1,P2,P3,P4)
• IsEmailAddress(S1)
• IsNull(P1)
• IsNullDefault(S1, S2)
• IsPhoneNumber(P1)
• Length(V1)
• LiveContentMicrositeURL(S1, S2)
• LocalDateToSystemDate(S1)
• LongSFID(S1)
• Lookup(S1, S2, S3, S4)
• LookupOrderedRows(S1, N1, S2, S3, S4)
• LookupOrderedRowsCS(S1, N1, S2, S3, S4)
• LookupRows(S1, S2, S3)
• LookupRowsCS(S1, S2, S3)
• Lowercase(S1)
• MD5(S1,S2)
• Mod(N1, N2)
• Multiply(N1, N2)
• Now(P1)
• Output(C1)
• OutputLine(C1)
• ProperCase(S1)
• QueryParameter(S1)
• RaiseError(S1,B1,S2,S3,B2)
• Random(I1, I2)
• Redirect(S1)
• RedirectTo(S1)
• RegExMatch(S1,S2,S3,S4...Sn)
• Replace(V1, S1, S2)
• ReplaceList(S1, S2, S3,...Sn)
• RequestParameter(P1)
• RetrieveMscrmRecords(S1,S2,S3a,S3b,S3c)
• RetrieveMscrmRecordsFetchXML(S1)
• RetrieveSalesforceJobSources(P1)
• RetrieveSalesforceObjects(S1,S2,S3a,S3b,S3c,...Sna,Snb,Snc)
• Row(RS, I1)
• RowCount(RS)
• Sending an Email Message to a Salesforce Object via AMPscript
• SetObjectProperty(O1,S1,S2)
• SetSmsConversationNextKeyword(S1,S2,S3)
• SetStateMscrmRecord(S1,S2,S3,S4)
• SHA256(S1,S2)
• SHA512(S1,S2)
• Special Attribute Types
• StringToDate(S1,S2)
• StringToHex(S1,S2)
• Substring(S1, I1, I2)
• Subtract(N1, N2)
• SystemDateToLocalDate(S1)
• TransformXML(S1,S2)
• TreatAsContent(S1)
• TreatAsContentArea(S1,S2,S3)
• Trim(S1)
• UpdateData(S1, N1, S2, S3, S4, S5)
• UpdateDE(S1, N1, S2, S3, S4, S5)
• UpdateMscrmRecords(S1,S2,S3a,S3b...SNa,SNb)
• UpdateSingleSalesforceObject(S1,S2,S3a,S3b,...Sna,Snb)
• Uppercase (S1)
• UpsertContacts(S1,S2,S3,S4,S5...)
• UpsertData(S1, N1, S2, S3, S4, S5)
• UpsertDE(S1, N1, S2, S3, S4, S5)
• UpsertMscrmRecord(S1,S2,S3,S4,S5a,S5b,S6a,S6b)
• URLEncode(S1,B1)
• V(S1)
• WAT and WATP (S1, S2)
• WrapLongURL(S1)
UpdateMscrmRecords(S1,S2,S3a,S3b...SNa,SNb)
Updates one or more records in a Microsoft Dynamics CRM entity. Also returns the number of records that
were successfully updates.
Arguments
• S1 The name of the Microsoft Dynamics CRM entity receiving the updated records
%%[
/* Sample Code - this updates several lead records to have Web as a Lead
Source Code in Dynamics CRM */
var @records_updated
]%%
%%=v(@records_updated)=%%
UpsertMscrmRecord(S1,S2,S3,S4,S5a,S5b,S6a,S6b)
Retrieves a single record from Microsoft Dynamics CRM and sorts them using the sort field and order
provided. Updates records based on Name and Value attributes. If no record is found, one is created using
Name and Value attributes. Returns the GUID of the updated or created record.
Arguments
• S1 The name of the Dynamics CRM entity for the record to upsert
• S2 The field used to sort the retrieve results
• S3 The order used to sort the retrieve results (ASC|DSC)
• S4 The number of Name/Value pairs of fields used to retrieve
• S5a, S5b Name/Value pairs of attributes to filter on the target entity
• S5a, S5b Name/Value pairs of attributes to update on the target record
CreateMscrmRecord(S1,S2,S3a,S3b)
Creates a single Dynamics CRM record in the target entity. Returns the GUID of the created record.
Arguments
• S1 The name of the Dynamics CRM entity for the record to create
• S2 The number of Name/Value pairs of fields to populate on the created record
• S3a, S3b Name/Value pairs of attributes to populate on the created record
%%[
var @contact_guid
]%%
%%=v(@contact_guid)=%%
RetrieveMscrmRecords(S1,S2,S3a,S3b,S3c)
Retrieves multiple CRM records. Use fields in the target entity or select fields from related entities by using
Many:1 lookup attributes.
Arguments
• S1 The name of the Dynamics CRM entity from which to retrieve records
• S2 A comma-separated list of fields to retrieve
• S3a, S3b, S3c Field to check value of, operator, and value
Example
You can select the name of the parent account by including parentaccount.id name in the list of fields. You
can also filter on Many:1 lookup attributes by using the same nomenclature. To retrieve accounts where
the parent account's name is Example.com, include "parentaccountid.name","=","Example.com" in your
filters. All values regularly retrieved in Fetch XML queries are returned. If parentaccount.id is one of the
fields to be returned, the results will have columns parentaccountid, parentaccountid.name, and
parentaccountid.type.
%%[
/* Sample Code - this retrieves all contacts where the first name is John
*/
]%%
<p>Contacts:</p><br><br>
%%[
]%%
RetrieveMscrmRecordsFetchXML(S1)
Takes a correctly formed Fetch XML query and returns the attributes specified in the query.
Arguments
• S1 Microsoft Dynamics CRM Fetch XML query
DescribeMscrmEntities()
Returns the logical name and display name of all Microsoft Dynamics CRM entities
Example
%%[
var @entities_rs
]%%
%%[
]%%
DescribeMscrmEntityAttributes(S1)
Returns the logical name, display name, and type of the Dynamics CRM entity. If the attribute is Boolean,
status, a picklist, or a state, the function returns a comma-separated list of option and display values.
Arguments
S1 The Dynamics CRM entity from which to retrieve attributes
%%[
var @fields_rs
]%%
%%[
]%%
AddMscrmListMember(S1,S2)
Adds the indicated record to the indicated marketing list. No return value.
Arguments
• S1 The GUID of the record to add to the marketing list
• S2 The GUID of the marketing list receiving the marketing list
%%[
AddMscrmListMember(@guid, @list_guid)
]%%
SetStateMscrmRecord(S1,S2,S3,S4)
Sets state and status of the indicated record. Provides "-1" as the status value for the state's default status.
No return value.
Some entities, including Opportunity, require special CRM requests to change their state. This method will
not work for those entities.
Arguments
• S1 The GUID of the record to set the state and status for
• S2 The Dynamics CRM entity name of the record
• S3 The state to set, such as "Active" or "Inactive"
• S4 The status to set, such as "1" or "0"
%%[
SetStateMscrmRecord(“00000000-0000-0000-0000-000000000001”, “account”,
“Inactive”, “-1”)
]%%
Party List
By including |partyentityname (substituting your name for the text following the pipe) at the end of a
series of fields and values, you can create a record on the party list with those fields and values. Only one
record will be created, but any values (except for another party list) can be populated. This attribute is
specifically for use with campaign responses, and the party list maps directly to the customer field on a
campaign response.
Example
"field,value,field2,value2"|examplepartylist
The above text would create a record on example partylist with two fields (field and field 2) assigned
different values (value and value2, respectively).
This document contains conceptual and procedural information regarding the use of AMPscript functions
with your instance of Salesforce.com.
When passing in objects from your Salesforce instance, you can use Salesforce dot notation within the
AMPscript functions. For example:
RetrieveSalesforceObjects("contact","account.name,FirstName,LastName,account.id",
"=", "smith")
This above function pulls the account name and account ID from your Salesforce instance.
CreateSalesforceObject(S1,I1,S2a,S2b,...Sna,Snb)
Creates a record in your integrated Salesforce account and returns the ID of the record created. This
function works only if your account is integrated with a Salesforce account.
Arguments
• S1 The type of object to create a record in. For example, Lead or CustomObject__c
• I1 The number of fields you are specifying in the record to add.
• S2a…Sna The name of the field (from Salesforce) that you are specifying.
• S2b…Snb The value of the field.
Example
The system creates a lead in the integrated Salesforce account where the FirstName field contains Chris
and the LastName field contains Cruz.
RetrieveSalesforceJobSources(P1)
Returns a record set with three columns from the job with the specified ID. The three columns are listed
below:
1. SourceID
2. SourceType
3. IsInclusionSource
Arguments
• P1 jobID
Notes
This function does not return any information on the status of the job itself. For example, the function will
return the same information from a completed job as it does from a job that was started and then canceled.
This information should not be used as a guarantee that the send was completed.
RetrieveSalesforceObjects(S1,S2,S3a,S3b,S3c,...Sna,Snb,Snc)
Returns a record set with the selected information from Salesforce objects that match the criteria you
specify. This function works only if your account is integrated with a Salesforce account.
Arguments
• S1 The type of object from which to retrieve information. For example, Lead or CustomObject __C
• S2 The names of the fields from which to retrieve information. This variable can contain multiple
comma-separated field names. For example, “FirstName,LastName”
• S3a…Sna The names of the fields to use to match the record for selection (the WHERE clause).
This variable contains only one field name. For example, if you enter FirstName for the S3a
variable, the system will select records based on the value in the FirstName field.
• S3b…Snb The operator to use to compare the value in the S3a field to the value you enter in the
S3c field. Valid values include:
◦ = (is equal to)
◦ < (is less than)
◦ > (is greater than)
◦ != (is not equal to)
◦ <= (is less than or equal to)
◦ >= (is greater than or equal to)
• S3c…Snc The value to which to compare the S3a field value for record selection.
Example
The system returns the first name and last name of all leads in your Salesforce account where the region
equals west.
LongSFID(S1)
Returns the 18-character Salesforce ID from a shortened 15-character version.
Argument
• S1 The 15-character Salesforce ID
Example
The example below returns the value of 0036000000QKv5TAAT.
%%=LongSFID("0036000000QKv5T")=%%
UpdateSingleSalesforceObject(S1,S2,S3a,S3b,...Sna,Snb)
Updates a record in an object in your integrated Salesforce account. This function works only if your
account is integrated with a Salesforce account. Returns 1 for success or 0 for failure.
Arguments
• S1 The type of object to update. For example, Lead or CustomObject__C.
• S2 The ID of the object to update.
• S3a…Sna The name of the field to update.
• S3b…Snb The value to update the field with.
Example
%%[
var @result
set @result =
UpdateSingleSalesforceObject("Lead","00300003yAEj","Email","jcc@example.com")
]%%
The system updates the Email field on the Lead with ID 00300003yAEj to contain jcc@example.com.
%%[
var @senddef, @msg, @sc
Set @senddef = CreateObject("EmailSendDefinition")
SetObjectProperty(@senddef, "CustomerKey", "SFSend")
%%=v(@sc)=%%
<br />
%%=v(@msg)=%%
clicks a link in an email message, that link takes them to a landing page that includes the AMPscript below.
The landing pages accepts the LeadID provided by the click and updates the campaign status accordingly.
Set @Result =
UpdateSingleSalesforceObject("CampaignMember",@CamMemId,"Status","RSVP-Yes")
]%%
<br />
Thank you %%=v(@FirstName)=%% %%=v(@LastName)=%% for signing up for the
our webinar!
AddObjectArrayItem(O1,S1,S2)
Appends an object to an array on an API object.
Arguments
• O1 The API object containing the array
• S1 The array property to which an item is to be added
• S2 The item to be added to the array
Example
Given the example below:
AddObjectArrayItem(@mySubscriber,“Attribute”,@myNewAttribute)
The Attributes array on the mySubscriberObject would receive the attribute myNewAttribute.
CreateObject(S1)
Returns a new ExactTarget web service API object.
Arguments
• S1 The API Object receiving the new item in text form
Example
An object created with CreateObject() should only be used for one particular API call. So, if a Subscriber
object is created and then updated via InvokeUpdate, it cannot be passed to a Triggered Send.
Field(S1,S2)
Returns the specified field in the specified row or property value from an API object.
Arguments
• S1 Row from which to return the field, or object from which to return the attribute
• S2 Name of the field or attribute to return
Example
%%=Field(@row, "City")=%%
The system returns value of the City field in the row specified in the @row variable.
%%=Field(@subscriber, "EmailAddress")=%%
The system returns the EmailAddress value from the @subscriber WSDL object.
InvokeCreate(O1,S1,N1,O2)
Invokes the ExactTarget web service API Create method on an API object. Returns the API Status Code.
Arguments
• O1 The API object to be created
• S1 Output parameter for the API status message
• N1 Output parameter for the API error code
• O2 The CreateOptions API call
Example
Given the example below:
%%[
var @emailaddr
SET @emailaddr = "help@example.com"
]%%
The AMPscript creates the TriggeredSend and TriggeredSendDefinition objects as @ts and @tsDef. It also
assigns the correct properties to the objects and passes the object into the InvokeCreate call. The
InvokeCreate call returns a status code and status message by which exception handling can be built. In
this example, the AMPscript returns an error to the screen.
InvokeDelete(O1,S1,N1,O2)
Invokes the Delete method on an API object. Returns the API Status Code.
Arguments
• P1 The API object to be executed
• P2 The output parameter used to get the status (optional)
• P3 The output parameter used to get the request ID (optional)
Example
Given the example below:
SetObjectProperty(@lue,"Name","LogUnsubEvent")
SET @lue_prop =
CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name",
"SubscriberKey")
SetObjectProperty(@lue_prop, "Value",
@SubscriberID)
AddObjectArrayItem(@lue, "Parameters",
@lue_prop)
SET @lue_prop =
CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name",
"JobID")
SetObjectProperty(@lue_prop, "Value",
@JobID)
AddObjectArrayItem(@lue, "Parameters",
@lue_prop)
SET @lue_prop =
CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name",
"ListID")
SetObjectProperty(@lue_prop, "Value",
@ListID)
AddObjectArrayItem(@lue, "Parameters",
@lue_prop)
SET @lue_prop =
CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name",
"BatchID")
SetObjectProperty(@lue_prop, "Value",
@BatchID)
AddObjectArrayItem(@lue, "Parameters",
@lue_prop)
SET @lue_prop =
CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name",
"Reason")
SetObjectProperty(@lue_prop, "Value",
"Custom Unsubscribe Page")
AddObjectArrayItem(@lue, "Parameters",
@lue_prop)
The code sets up and executes a LogUnsubEvent and succeeds if the operation completes (or when the
specified error codes indicate the subscriber was already unsubscribed).
InvokePerform(O1,S1,S2)
Invokes the ExactTarget web service API Perform method on an API object. Returns the API Status Code.
Arguments
• O1 The API object to be performed
• S1 The action to be performed – valid parameter values vary depending on object type
Arguments
• P1 The RetrieveRequest object from which you wish to return an array of API objects.
• P2 (Optional) The OverallStatus parameter passes the Status of the retrieve call to a previously
defined AMPscript variable.
• P3 (Optional) The RequestID parameter passes the RequestID of the retrieve call to a previously
defined AMPscript variable.
InvokeUpdate(P1,P2,P3,P4)
Invokes the Update method on an API object.
Arguments
• P1 Text object for the API object
• P2 StatusMessage – optional text status message
• P3 ErrorCode – optional numeric error code
• P4 Options – optional options in text
RaiseError(S1,B1,S2,S3,B2)
Raises the error given in S1 and stops processing of job. If optional B1 is included with a value of true, this
function stops the send for the current subscriber only.
Arguments
• S1 The error message to be displayed
• B1 Optional – a value of true stops the send for the current subscriber only
• S2 Optional – displays API Error Code
• S3 Optional – displays API Error Number
• B2 Optional - records information written to data extension before the error occurs. A value of 1
retains information written to data extensions before the error occurs, even if the subscriber is
skipped.
The B2 flag applies to data written by the following AMPscript functions:
• InsertDE
• InsertData
• UpdateDE
• UpdateData
• UpsertDE
• UpsertData
• DeleteDE
• DeleteData
Example
System returns the error message “An Error Occurred” and stops the job.
System returns the error message “Do not send to subscriber” and stops the send to that subscriber only.
Please note that because the system pre-processes and builds these emails, tracking and reporting
numbers include these emails despite the errors and may cause inaccuracies. Use this function to handle
the errors of a small number of subscribers, rather than as a method to segment out large numbers of
subscribers. Instead, use query activities and exclusion lists to handle your segmentation needs.
SetObjectProperty(O1,S1,S2)
Sets a value for an object created by the CreateObject function.
Arguments
• O1 The API object receiving the assigned value
• S1 The name of the property being assigned
• S2 The value of the property being assigned
Example
The following example creates an API object named “Subscriber” and gives it the “EmailAddress” property
with the value of an email address.
SET @subscriber=CreateObject(“Subscriber”)
SetObjectProperty(@subscriber,”EmailAddress”,”user@example.com”)
The following example creates an API object named "Attribute", gives it a name of "First Name", and sets
the value to John.
SET @attribute=CreateObject(Attribute)
SetObjectProperty(@attribute,"Name","First Name")
SetObjectProperty(@attribute,"Value","John")
AttachFile(S1,S2,S3,B1,S4,S5,N1)
AMPscript email attachments must be enabled in your account before you can use this function. Contact
ExactTarget if you would like this feature enabled in your account. You should also contact ExactTarget to
adjust the threshold of errors that cause the send job to stop prematurely. This could be helpful in
preventing a single error from stopping the entire job.
Attaches a file to an outgoing email message and can include a link to the file when you view the email as a
web page:
Arguments
• S1 Indicates whether to pull files from an HTTP source, the ExactTarget Enhanced FTP site, or the
portfolio. Valid values include:
◦ HTTP
◦ FTP
◦ Portfolio
• S2 Indicates from where the function pulls the attachment. These files must be available at the
time of the send, or else your send will encounter an error.
◦ If S1 is HTTP, S2 is the URL of your file.
◦ If S1 is FTP, S2 is the name of the file in the Import folder of your Enhanced FTP site.
◦ If S1 is Portfolio, S2 is the External Key of the item in your Portfolio folder.
• S3 Indicates the name to give the file when it is attached to the email. This argument is optional
and will use the current attachment’s name if none is specified.
• B1 Indicates whether a link to attached file is seen in View As A Web Page. This argument is
optional and only used if S1 is HTTP.
• S4 Sets the URL of the attachment link to be used for View As A Web Page. This argument is
optional and only used if S1 is HTTP.
• S5 Sets the text for the attachment link to be used in View As A Web Page. This argument is
optional and only used if S1 is HTTP.
• N1 Sets the number of days the link attachment will be seen in View As A Web Page. This
argument is optional and only used if S1 is HTTP.
Examples
The following example attaches a PDF document from a website to your outgoing email. The email also
includes a link to the file in View As A Web Page with the text “Click here to download your catalog.” That
link expires from View As A Web Page after four days.
%%=AttachFile(“HTTP”,“http://example.com/
catalog.pdf”,true,“http://example.com/catalog.pdf”,“Click here to
download your catalog”,4)=%%
If you want to rename the attachment, enter the optional filename argument as shown below:
%%=AttachFile(“HTTP”,“http://example.com/
catalog.pdf”,"newFileName.pdf",true,“http://example.com/
catalog.pdf”,“Click here to download your catalog”,4)=%%
The next example attaches a Word document from the import folder of the ExactTarget Enhanced FTP
site. It also concatenates a new filename from the recipient’s full name and the string “NewCatalog.doc” at
the time of attachment.
%%=AttachFile(”FTP”,”productCatalog.doc”,Concat(FullName,”NewCatalog.doc”))=%%
The following file types can be attached to emails sent through ExactTarget :
BarCodeURL(S1,S2,N1,N2,S3)
Takes the information supplied in the function and generates the specified bar code.
This function requires additional configuration by ExactTarget for use in your account. Your account must
also be enabled to use the Live Content feature. Please contact your ExactTarget representative for more
information on enabling this feature.
Arguments
• S1 Value to be converted into a bar code
• S2 Type of bar code to create - possible values listed below:
◦ Codabar
◦ Code11
◦ Code128Auto
◦ Code128A
◦ Code128B
◦ Code128C
◦ Code39
◦ Code39Ext
◦ Code93
◦ Code93Ext
◦ Ean13
◦ Ean8
◦ Industr25
◦ Interl25
◦ Mat25
◦ MSI
◦ Postnet
◦ Planet
◦ Telepen
◦ UPCa
◦ UPCe
◦ OneCode
◦ Data Matrix
◦ PDF417
◦ PlainText
• N1 Height of bar code in pixels
• N2 Width of bar code in pixels
• S3 Checksum value for bar code (optional)
• B1 Display bar code value from S1 as text
◦ 0 Displays the alt text provided in the S4 value
◦ 1 Displays the S1 value as text with the barcode
• S4 Alt text to display if B1 contains a value of 1
• N3 Orientation of the bar code
◦ 0 Display bar code horizontally (default)
◦ 90 Display bar code rotated 90˚ to the right
◦ 180 Display bar code rotated 180˚
◦ 270 Display bar code rotated 90˚ to the left
• B1 Display a transparent background for the barcode
◦ 0 Do not display a transparent background
◦ 1 Display a transparent background
Example
When the AMPscript below is placed in a content area, the email messages receives the applicable bar code
at the time of the send:
<p>
<img style="width: 400px; height: 200px" title=barcode border=0
hspace=0 alt=barcode src='%%=BarCodeURL("BBY01-397101069285","Code39",
400, 200, 0)=%%' width=400 height=200>
</p>
The AMPscript generates a bar code based on the value in Code39 format in the specified height and width.
The AMPscript below displays the bar code with the listed alt text and rotated 90˚ to the right on a
transparent background.
The AMPscript below displays the bar code with the S1 value as text and rotated 90˚ to the right on a
transparent background. Note that the single quotes must be included when using the S1 value as text to
prevent the function from returning an error.
BeginImpressionRegion(S1)
Denotes the beginning of a region to be tracked with impression tracking.
Arguments
• S1 Name of the impression region
Example
%%=BeginImpressionRegion(Header)=%%
BuildOptionList(S1,S2,S3)
Builds a list of options from which a message recipient can select.
Arguments
• S1 Value of this variable determines which option will be selected by default
• S2 Value of first option on list
• S3 Presentation name of first option on list
S2 and S3 are repeated for each option on the list.
Example
Given attribA=2
<option value="1">One</option>
<option value="2" selected="selected">Two</option>
<option value="3">Three</option>
BuildRowSetFromString(S1,S2)
Creates a rowset from a character string by splitting the string at the specified delimiter.
BuildRowsetFromString("123|456|789", "|")
123
456
789
The sample code below demonstrates how to pass attribute names and process them:
%%[
Var @queryparams
Var @row
Var @name
Var @value
for @i = 1 to Rowcount(@queryparams) do
Set @row = Row(@queryparams, @i)
Set @name = Field(@row,1)
Set @value = QueryParameter(@name)
]%%
Passed <b>name:</b> %%= v(@name) =%% with <b>value:</b> %%= v(@value)
=%%<br/>
%%[
next @i
]%%
names=career|firstname|lastname&career=marketer&firstname=Angela&lastname=Ruiz
This function returns the rowset in one column, and this column does not have an assigned name. When
referring to this column within a function (such as the example listed below), you must refer to the column
with an ordinal number:
BuildRowSetFromXML(S1,S2,B1)
Creates a rowset from XML, and can return an empty rowset on error. This function is for use at send time
only.
Value: Value of the node (empty for CDATA, Comment, Document, Document Fragments, DocumentType,
Entities, Entity References, Notation, ProcessingInformation, Whitespace, and XmlDeclaration nodes) For
element nodes, this is the text of the node.
XML: Any XML contained within the node (empty, if the node does not contain XML).
Also provides a column for each attribute found in any of the nodes. If a node is missing a value for that
attribute, an empty value is returned.
Arguments
• S1 XML within the node
• S2 XPATH argument
• B1 The returnEmptyRowsetOnError, specified as a Boolean
Example
Given the @xml variable contains the following text:
<root>
<Flight origin="IND" dest="NYC">100.00</Flight>
<Flight origin="IND" dest="LAX" carrier="UAL">200.00</Flight>
<Flight origin="IND"
dest="SEA">500<PerBagSurcharge>25</PerBagSurcharge></Flight>
</root>
BuildRowsetFromXml(@xml, "//Flight", 1)
ContentArea(I1,S1,B1,S2,N1)
Returns content contained in the specified stored content area.
Arguments
• I1 The ID of the content area to return.
• S1 Impression region name. Use this optional parameter for impression tracking. Setting an
impression region this way is the same as using the BeginImpressionRegion() function as the first
statement in the content area. Impression regions started this way remain open after the function
executes.
• B1 The ThrowError value defaults to true. When the value is true, the function throws an error If
the specified content area is not found or not valid. If the value is false, the function uses the value
of the DefaultContent parameter instead of throwing an error. This parameter is optional.
• S3 The DefaultContent value defaults to an empty string. If the ThrowError value is false, the
DefaultContent value is used. This parameter is optional.
• N1 This output parameter returns the status of the call (optional). Possible values include:
◦ 0 The content area was found and successfully rendered
◦ -1 Either the content area was not found or not valid. In this case, the function returns
the DefaultContent value.
Example
%%=ContentArea("14")=%%
ContentAreaByName(S1,S2,B1,S3,N1)
Returns the content contained in the specified stored content area.
Arguments
• S1 Name of the content area for which to return content. If the content area is stored in a folder
within the my contents folder, the name includes the path to the content area.
• S2 Impression region name. Use this optional parameter for impression tracking. Setting an
impression region this way is the same as using the BeginImpressionRegion() function as the first
statement in the content area. Impression regions started this way remain open after the function
executes.
• B1 The ThrowError value defaults to true. When the value is true, the function throws an error If
the specified content area is not found or not valid. If the value is false, the function uses the value
of the DefaultContent parameter instead of throwing an error. This parameter is optional.
• S3 The DefaultContent value defaults to an empty string. If the ThrowError value is false, the
DefaultContent value is used. This parameter is optional.
• N1 This output parameter returns the status of the call (optional). Possible values include:
◦ 0 The content area was found and successfully rendered
◦ -1 Either the content area was not found or not valid. In this case, the function returns
the DefaultContent value.
Example
The system returns the content of stored content area named Weekly Portfolio in the Stocks folder.
In this example:
The function displays the Opt Out Form Default page if no other content is found.
This example concatenates the base content area name with a Locale ID to provide an opt-out form in the
appropriate language. If no Locale ID is specified, the function defaults to EN-US.
EndImpressionRegion(B1)
Identifies the end of a region to be tracked by impression tracking.
Arguments
• B1 If the optional Boolean is set to true, all impression areas are closed. If an impression region is
not explicitly closed, it will be implicitly closed at the end of the message being built.
Example
%%=EndImpressionRegion()=%%
GetPortfolioItem(S1)
Returns the text value of a Portfolio item.
Arguments
• S1 External Key of the Portfolio item
Example
Given the Portfolio item of example.gif:
GetPortfolioItem("example.gif")
Image(S1,S2)
Returns an img tag with the src attribute containing the path to an image from your portfolio. You identify
the image to include with the External Key value. The img tag includes the width and height you chose
when you imported the image. If the value of S1 does not link to a valid image, you can include another
image value for S2 as a default option.
Arguments
• S1 External Key value of the image in your portfolio
• S2 (Optional) External Key value of a default image to use if S1 is not found
Example
%%=Image("CorpLogo","DefaultImage")=%%
System returns:
If, for some reason, the CorpLogo image could not be retrieved, system returns:
Row(RS, I1)
Returns specified row from specified rowset or array.
Arguments
• RS The rowset
• I1 The count of the row to return
Example
%%=Row(@Rowset,1)=%%
System returns the first row of the rowset contained in the @Rowset variable.
RowCount(RS)
Returns the number of rows in a specified rowset or array.
Arguments
• RS The rowset
Example
%%=RowCount(LookupRows("PostalCode","City","Indianapolis"))=%%
System returns the number of rows in the PostalCode data extension whose City column contains the value
Indianapolis.
SetSmsConversationNextKeyword(S1,S2,S3)
Sets the keyword for the next conversation path based on an SMS response from an MO user. This can be
the current keyword or a new keyword for a different conversation path.
Arguments
• S1 The short code of the SMS service
• S2 This string can pass in the MOBILE_NUMBER variable for the user’s mobile number
• S3 The keyword name to set as the next conversation keyword
Example
During a conversation between the MT user and the MO user, this example will change to the conversation
path indicated by the EXAMPLE keyword.
%%=SetSmsConversationNextKeyword(“12345”,MOBILE_NUMBER,”EXAMPLE”)=%%
The conversation is moved to the new path indicated and proceeds from there. Please note that this
example does not execute the set keyword immediately; it sets the keyword to handle the next message
from the MO user.
TransformXML(S1,S2)
Applies an XSL transform to an XML document.
Arguments
• S1 The XML to be transformed
• S2 The XSL document to be used in the transformation
Example
Given the example.xml and the transform.xsl files
%%=
TransformXML(GetPortfolioItem("formGenXML"),GetPortfolioItem("formGenXSL"))
=%%
The function uses the GetPortfolioItem() functions to retrieve the formGenXML and formGenXSL files from
Portfolio. The ExactTarget application then applies the formGenXSL file to the formGenXML file as part of
the transformation process.
TreatAsContent(S1)
Treats the string as though it had come in from a content area.
To retrive tracking information associated with these strings, you should wrap the embedded links within
your HTML content using the RedirectTo() function and use the TreatAsContent() function to treat your
string as if it came from a content areas.
Arguments
• S1 String to return
TreatAsContent(Field(@row,"Content"))
Returns
A string of text which, if personalization strings are included, will replace those strings with the
appropriate data.
TreatAsContentArea(S1,S2,S3)
Treats content retrieved from a data extension or other source as though it is fixed content coming from a
content area.
Arguments
• S1 A key value to be used to identify the content specified in the second string. You can use the
same key to identify distinct text and HTML versions of the content, as a key in a text content is
considered distinct from a key in a HTML context. The application processes all keys in a case-
insensitive manner.
• S2 Content to be stored for an email send under the key specified in the first string. You can
retrieve content using the HTTPGET() or Lookup() AMPscript functions.
• S3 (optional) The impression region name for the virtual content area to be used for tracking
purposes.
Once you specify a key value for content retrieved using this function and process it to build subscriber
messages, that information becomes read-only. Future calls using that key result in the same information
as specified the first time the call was made. Each email has a limit of 300 virtual content areas created
through this function. If you exceed the limit, the additional calls will behave similarly to the
TreatAsContent() function and further virtual content areas will not be created for any additional keys.
Because a triggered send uses the same JobID for all sends, this function can exceed the 300 virtual content
area limit and result in problems providing accurate tracking information. In this case, you should wrap
the embedded links within your HTML content using the RedirectTo() function and use the
TreatAsContent() function to treat your string as if it came from a content areas.
If you have enabled link tracking, the links, forms and calls to ExactTarget landing pages will be wrapped
in order to provide tracking information. You can use the virtual content areas created via this call both
for other emails in the send using the virtual content area key and for building post-send content (such as
View As A Web Page).
Use TreatAsContentArea() when you are sending content to a large number of subscribers, and
use TreatAsContent() when sending content unique to a single subscriber.
Example
The sample code below pulls content from a data extension and saves it for reuse as a virtual content area
under the key VirtualCA1:
%%=TreatAsContentArea(“VirtualCA1”, Lookup(“DEName”,
“DEContentColumn”,”KeyField”, KeyValue))=%%
The sample code below pulls content from a data extension and saves it for reuse as a virtual content area
under a key specified through the KeyValue attribute or data extension field.
%%=TreatAsContentArea(KeyValue, Lookup(“DEName”,
“DEContentColumn”,”KeyField”, KeyValue))=%%
The sample code below pulls content from a data extension, saves it for reuse as a virtual content area
under the key VirtualCA1, and assigns it the impression region name of Impression Region One:
%%=TreatAsContentArea(“VirtualCA1”, Lookup(“DEName”,
“DEContentColumn”,”KeyField”, KeyValue), “Impression Region One”)=%%
Arguments
• S1 String to perform the match against
• S2 Value with which to replace the WATP function tracking parameter
Example
WAT("Omniture","1234")
Returns the value of the Omniture tracking parameter with 1234 substituted for references to WATP(1)
within the tracking parameter
ClaimRow(S1,S2,S3,S4,...Sn,Sn+1)
Returns a row from a data extension and locks the row to prevent the information from being used in
another context until the row's "claimed" status changes. If the function finds a row with the correct
matching set of keys, the function returns those values. If no claimed row is found, the function sets key
values in an unclaimed row and returns that row. If no row is returned by this function at all, you must set
up the function to raise an error, ignore the result, or provide default content.
The data extensions used with this function must possess the following characteristics:
• A Boolean column that indicates whether the row has been claimed or not (a true value indicates
the row as claimed)
• An index on the Boolean and _CustomObjectKey columns to allow for an efficient lookup of
claimed rows
• One or more key columns used to identify the object or recipient that has claimed or is claiming
the row (this column must be nullable)
• An index on the key column or columns to allow an efficient lookup of claimed rows
The application automatically sets indexes on sendable data extensions, and you should contact your
ExactTarget representative to set indexes for non-sendable data extensions.
You can also include an optional column to receive a datetime stamp at the time the application executes
the ClaimedRow() function. You must name this column ClaimedDate and assign it the Date data type.
When this column exists, the ClaimedDate value in that row receives the datetime stamp for when that
row was claimed.
You cannot overwrite or delete the data extension with a claimed status.
Arguments
• S1 The name of the data extension for the claim or retrieve action
• S2 The name of the column in the data extension that indicates whether the row is claimed or not
• S3 The name of the data extension key column
• S4 The value of the data extension key column
You can specify multiple pairs of column names and values, depending on your needs.
Example
The code below claims a row or retrieves the information from a previously claimed row. If no row
matches the specified values, the function indicates no coupon codes are available.
<table>
<tr>
<td>Coupon Code (ClaimRow)</td>
<td>
%%[VAR @CouponRow
Use the example data extension below as a model for the data extension you use to store and claim rows:
Default
Column Name Type Null
Value
CouponCode nvarchar(30) No
IsClaimed Boolean No 0
ClaimRowValue(S1,S2,S3,S4,S5,S6,...Sn, Sn+1)
Returns a value from a column in an data extension and locks the row to prevent the information from
being used in another context until the value's "claimed" status changes. If the function finds a value with
the correct matching set of keys, the function returns the requested column value. If no row is found, the
function attempts to claim an unused row. If a row cannot be found or claimed, the function returns the
specified default value. Otherwise, the function returns an error.
The data extensions used with this function must possess the following characteristics:
• A Boolean column that indicates whether the row has been claimed or not (a true value indicates
the row as claimed)
• An index on the Boolean and _CustomObjectKey columns to allow for an efficient lookup of
claimed rows
• One or more key columns used to identify the object or recipient that has claimed or is claiming
the row (this column must be nullable)
• An index on the key column or columns to allow an efficient lookup of claimed rows
The application automatically sets indexes on sendable data extensions, and you should contact your
ExactTargetrepresentative to set indexes for non-sendable data extensions
You can also include an optional column to receive a datetime stamp at the time the application executes
the ClaimedRowValue() function. You must name this column ClaimedDate and assign it the Date data
type. When this column exists, the ClaimedDate value in that row receives the datetime stamp for when
the value and row were claimed.
You cannot overwrite or delete the data extension with a "claimed" status.
Arguments
• S1 The name of the data extension for the claim or retrieve action
• S2 The name of the column in the data extension from which the return value is retrieved
• S3 The name of the column in the data extension that indicates whether the row is claimed or not
• S4 (Optional) The default value to use in case the function fails to claim a row
• S5 The name of the data extension key column
• S6 The value of the data extension key column
You can specify multiple pairs of column names and values, depending on your needs. If no row is returned
by this function, you must set up the function to raise an error, ignore the result, or provide default
content.
Example
The sample below retrieves the same information from the same row any time a specific job sends to a
specific recipient.
<table>
<tr>
<td>Coupon Code (ClaimRowValue no default)</td>
<td>%%= ClaimRowValue("Coupon", "CouponCode", "IsClaimed", ,
"JobID", JobID, "ListID", ListID, "SubscriberID", SubscriberID) =%%</td>
</tr>
</table>
The sample below retrieves a distinct row each time a specific job sends to a specific recipient. If the
function does not find an appropriate value, it uses the provided default information.
<table>
<tr>
<td>Coupon Code (ClaimRowValue with default)</td>
<td>%%= ClaimRowValue("Coupon", "CouponCode", "IsClaimed", "None
Use the example data extension below as a model for the data extension you use to store and claim rows:
Default
Column Name Type Null
Value
CouponCode nvarchar(30) No
IsClaimed Boolean No 0
Arguments
• S1 The name of the data extension from which to delete the specified row
• S2 Name of the column to use to identify the rows to delete.
• S3 Value to use to identify the rows to delete.
Example
DeleteDE("SendDE", "_SubscriberKey","12345")
ExecuteFilter(S1,S2,S3...)
Executes a predefined data filter and returns a rowset containing the results.The data source for the data
filter must be a data extension. If a parameterized data filter is used, you must provide name and value
pairs for all parameters defined within the data filter.
Arguments
• S1 The external key of the data filter to be executed
ExecuteFilter("ExampleDataFilter","IsActive","TRUE","FirstName","John")
The system returns all applicable rowsets with a value of TRUE for IsActive and a value of John for
FirstName.
ExecuteFilterOrderedRows(S1,N1,S2,S3,S4...)
Executes a predefined data filter and returns a rowset containing the results.The data source for the data
filter must be a data extension. If a parameterized data filter is used, you must provide name and value
pairs for all parameters defined within the data filter. This function also allows you to control the sort
order and maximum number of rows in the resulting rowset.
Arguments
• S1 The external key of the data filter to be executed
• N1 The maximum number of rows to be returned; a value of 0 returns all rows
• S2 The name of the column by which the resulting rowset should be sorted
• S3 The name of a parameter defined in the data filter
• S4 The value to be used for a parameter defined in the data filter
Example
ExecuteFilter("ExampleDataFilter",5,"IsActive","IsActive","TRUE","FirstName","Joh
The system returns all applicable rowsets with a value of TRUE for IsActive and a value of John for
FirstName. The function returns only five rows, and those rows use the IsActive column to sort the
resulting rowset.
Arguments
• S1 The name of the data extension from which to insert the specified row
• S2, S3 Column name(s) and column value(s) to use to build the insert clause
Example
InsertDE("SomeDE","FirstName",FirstName, "LastName",LastName,
"CreatedDate",NOW())
%%=Lookup("PostalCode","City","PostalCode",46016)=%%
Returns the city associated with the postal code 46016 in the PostalCode data extension:
Anderson, IN
Arguments
• S1 The name of the data extension from which to return the specified rows
• N1 Number of rows to return. A 0 value indicates to return all matching rows.
• S2 Order clause in the following format: field [asc | desc] [, ... ]
• S3 Field to use to build the where clause
• S4 Value to use to build the where clause
Example
Arguments
• S1 The name of the data extension from which to return the specified rows
• N1 Number of rows to return. A 0 value indicates to return all matching rows.
• S2 Order clause in the following format: field [asc | desc] [, ... ]
• S3 Field to use to build the where clause
• S4 Value to use to build the where clause
Example
%%[
SET @Rows =
LOOKUPORDEREDROWS("CustomObject1",10,"Region","City","greenwood","SubscriberID",
100009)
SET @RowsCSF =
LOOKUPORDEREDROWSCS("CustomObject1",10,"Region","City","greenwood","SubscriberID"
100009)
SET @RowsCST =
LOOKUPORDEREDROWSCS("CustomObject1",10,"Region","City","Greenwood","SubscriberID"
100009)
]%%
Arguments
• S1 The name of the data extension from which to return the specified rows
• S2 Column name to match on to identify rows to return
• S3 Value to match S2 against
Example
LookupRows("ZipCode","City",HomeCity)
Returns the ZipCode rows where the City field matches for HomeCity value.
Arguments
• S1 The name of the data extension from which to return the specified rows
• S2 Column name to match on to identify rows to return
• S3 Value to match S2 against
]%%
Arguments
• S1 The name of the data extension from which to update the specified row
• N1 Number of columns used to build the where clause
• S2, S3 Column name(s) and column value(s) to use to build the where clause
• S4, S5 Column name(s) and column value(s) to use to build the insert clause
Example
UpdatedData("SendDE",1,"_SubscriberKey",_SubscriberKey,"DateSent",NOW())
Arguments
• S1 The name of the data extension from which to update the specified row
• N1 Number of columns used to build the where clause
• S2, S3 Column name(s) and column value(s) to use to build the where clause
• S4, S5 Column name(s) and column value(s) to use to build the insert clause
Example
UpdateDE("SendDE",1,"_SubscriberKey",_SubscriberKey,"DateSent",NOW())
Arguments
• S1 The name of the data extension from which to update the specified row
• N1 Number of filter columns to insert into or update
• S2, S3 Column name(s) and column value(s) to use to build the where clause
• S4, S5 Column name(s) and column value(s) to use to build the insert clause
Example
UpsertData("SendDE",1,"_SubscriberKey",_SubscriberKey,"DateSent",NOW())
Arguments
• S1 The name of the data extension from which to update the specified row
• N1 Number of filter columns used as part of the where clause
• S2, S3 Column name(s) and column value(s) to use to build the where clause
• S4, S5 Column name(s) and column value(s) to use to build the insert clause
Example
UpsertDE("SendDE",1,"_SubscriberKey",_SubscriberKey,"DateSent",NOW())
• Yes No
Suggestion:
Arguments
• D1 Date to add
• I1 Integer to add
• S1 Unit of time of the integer. Valid values include Y, M, D, H, and MI.
Example
%%=DateAdd(@today, "1","D")=%%
Arguments
• D1 The date from which to subtract D2
• D2 Date to subtract from D1
• S1 Unit of time of the difference. Valid values include Y, M, D, H, or MI
Example
%%=DateDiff(@tomorrow,@today, "D")=%%
System returns:
-1
DateParse(S1,B1)
Returns a DateTime object from a date string.
Arguments
• S1 The date string from which to derive the DateTime object
• B1 (Optional) Determines whether the DateTime object is returned as UTC
Example
DateParse("2009/10/17 02:30PM")
DateParse("2009/10/17 2:30PM-4:00",1)
System returns 6:30pm as the UTC time based off of the local time value.
DatePart(D1, S1)
Returns a specified part of a date.
Arguments
• D1 Date from which a specified part is retrieved.
• S1 The part of the date to retrieve. Valid values include year (Y), month (M), monthname, day (D),
hour (H), and minute (MI).
Example
%%=Datepart("5/1/2008","year")=%%
System returns:
2008
LocalDateToSystemDate(S1)
Converts a local datetime string or object to the system time.
Arguments
S1 The local time to convert
Example
%%[
VAR @currentSystemTime
SET @currentSystemTime = NOW()
]%%
Local Time For User: %%=SystemDateToLocalDate(@currentSystemTime)=%%
The system returns the local time based off of the value contained in the @currentSystemTime variable,
then converts it back to system time.
Now(P1)
Returns the current system date and time.
Arguments
• P1 Optional parameter. Enter 1 or true to indicate true to preserve the email sent time for post-
send resolution of Now.
Example
Given the date and time 10 a.m., March 1, 2008.
Now()
System returns:
3/1/2008 10:00:00
SystemDateToLocalDate(S1)
Converts a system datetime string or object to the user's local time.
Arguments
S1 The system time to convert
Example
%%[
VAR @currentSystemTime
SET @currentSystemTime = NOW()
]%%
Local Time For User: %%=SystemDateToLocalDate(@currentSystemTime)=%%
The system returns the local time based off of the value contained in the @currentSystemTime variable.
HTTPGet(S1,B1,N1,S2)
Returns the content from a specified URL. This function only works with HTTP on port 80 and HTTPS on
port 443. Non-standard port assignments cause this function to fail. ExactTarget honors any character set
returned in the HTTP headers via Content-Type. For example, you can use a UTF-8 encoded HTML file with
Content-Type: text/html; charset=utf-8 included in the header. If the encoding is not specified in the
header, the application assumes all returned data will be in the character set WindowsCodePage 1252.
You can change this default by contacting Global Support.
Arguments
• S1 The URL from which to return content
• B1 (Optional) Defines whether the process continues on error. Defaults to false. A value of true
ignores errors in process.
• N1 (Optional) Defines whether the function allows empty content. This function defaults to 0.
◦ A value of 0 allows for empty content
◦ A value of 1 returns an error
◦ A value of 2 skips the subscriber.
• S2 (Optional) Output of function status.
◦ A value of 0 indicates status is OK
◦ A value of -1 indicates a missing URL
◦ A value of -2 indicates an HTTP request error
◦ A value of -3 indicates empty content; the function completed successfully, but no content
was returned
Example
HTTPGet("http://www.example.com")
HTTPGet("http://www.example.com",false,0,@CallStatus)
System returns the content of http://www.example.com. The function stops if it encounters an error, and
it allows empty content. The status of the function is returned to the declared variable @CallStatus.
HTTPRequestHeader(S1)
Retrieves the specified header from an HTTP request. Can only be used in landing pages.
Arguments
• S1 The header to be retrieved from an HTTP request
%%=HTTPRequestHeader(“Referer”)=%%
System returns value of the Referer header from the HTTP request.
RedirectTo(S1)
Allows a client to specify the target of a link be a complete URL stored in an attribute, DE (data extension)
field, or variable. This function may be used only in HTML emails within the href attribute of an <A> tag. In
text emails, it must be prefixed with"http://" and there can be no spaces within the parentheses. In order
to retain tracking information for clicked links, you must include the anchor tags (<a></a>) within the
email itself and not the link retrieved via the AMPscript.
Arguments
• S1 Function or substitution string to which to redirect
Examples
Given the data extension Vacation_Deals:
%%[
Var @rows, @link, @cntr, @type
Set @rows=LookupRows("Vacation_Deals","CustomerID","123")
For @cntr=1 to Rowcount(@rows) do
set @type=Field(Row(@rows, @cntr),"type")
set @link=Field(Row(@rows, @cntr),"link")
]%%
<a href="%%=RedirectTo(@link)=%%">%%=v(@type)=%%</a>
%%[
Next @cntr
]%%
System returns:
Flight Deals
Car Deals
Where Flight Deals links to http://example.com/flights/ and Car Deals links to http://example.com/cars/.
You can also use this function to include data extension values at the end of a hyperlink within an email
message, as shown in the example below:
System returns:
https://www.example.com?email=aruiz@...com&name=Angel
URLEncode(S1,B1)
Returns the specified URL with spaces replaced with %20 or fully encodes all non-alphanumeric characters.
Arguments
• S1 String containing the URL and attribute value
• B1 (optional) If you do not specify this value, or if you set it to 0, the function replaces spaces in
the URL with %20. If you set this value to 1, the function full encodes all non-alphanumeric
characters in the string.
Example
URLEncode("http://example.com?p=first name")
System returns:
http://example.com?p=first%20name
WrapLongURL(S1)
Returns a wrapped URL for the long URL provided in the string parameter of the function. Only URLs
longer than 975 characters can be modified, and this function does not replace the standard link wrapping
functionality implemented in the ExactTarget application. It is intended to mitigate a known limitation
with long URLs in Microsoft Outlook 2007 and applies to URLs such as those included in an image source
tag.
Arguments
• S1 The long URL to be wrapped
Example
In the case where an image source URL exceeds 975 characters, use the function as shown below:
WrapLongURL("http://example.com/exceedinglylongimageurl.jpg")
This function returns a wrapped URL that can be used in your send to ensure compatibility with Outlook
2007. If this function is used on a URL with less than 975 characters, the URL will pass unchanged and the
call will not break the send. Links wrapped with WrapLongURL remain incompatible with Always On
Clicks. If your Member DB is down, a WrapLongURL will not work.
AuthenticatedEmployeeID()
Returns the employee ID of the authenticated landing page user.
Example
The system sets @ID to the value of the employee ID for the authenticated landing page user.
AuthenticatedEmployeeNotificationAddress()
Returns the notification email address of the authenticated landing page user.
Example
The system sets @address to the value of the notification email address for the authenticated landing page
user.
AuthenticatedEmployeeUserName()
Returns the username of the authenticated landing page user.
Example
The system sets @username to the value of the username for the authenticated landing page user.
AuthenticatedEnterpriseID()
Returns the enterprise ID of the authenticated landing page user.
The system sets @ID to the value of the enterprise ID for the authenticated landing page user.
AuthenticatedMemberID()
Returns the member ID of the authenticated landing page user.
Example
The system sets @ID to the value of the member ID for the authenticated landing page user.
AuthenticatedMemberName()
Returns the member name of the authenticated landing page user.
Example
The system sets @membername to the value of the member name for the authenticated landing page user.
Arguments
• S1 Data extension from which to delete the specified row
• S2 Name of the column to use to identify the rows to delete.
• S3 Value to use to identify the rows to delete.
Example
DeleteData("SendDE", "_SubscriberKey","12345")
The system deletes rows in the SendDE data extension whose _SubscriberKey column contains the value
12345 and returns the number of rows that were deleted.
Arguments
• S1 Data extension from which to insert the specified row
• S2, S3 Column name(s) and column value(s) to use to build the insert clause
InsertData("SomeDE","FirstName",FirstName, "LastName",LastName,
"CreatedDate",NOW())
IsNullDefault(S1, S2)
Returns the test data (S1) if it is not null. If null, S2 is returned. Primarily used by Smart Capture forms to
return a default value if a Smart Capture form value is not present or filled-in.
Arguments
• S1 The value to return if S1 is not null
• S2 The value to return if S1 is null
Example
LiveContentMicrositeURL(S1, S2)
Provides a way to return a microsite URL by referencing a coupon name that is being hosted on a
microsite.
Arguments
• S1 Content type - at this time, the only valid value for this argument is coupon
• S2 Name of the live content you are referencing
Example
%%=LiveContentMicrositeURL('coupon', 'MyCoupon')=%%
System returns:
QueryParameter(S1)
Retrieves the value from a query string, based on the key that was defined for it. This is a way for a page,
through the URL, to provide information on who is visiting a site.
Arguments
• S1 Key to pull value with
URL Example
http://example.com?j=Tim
AMPscript Example
SET@VAR=QUERYPARAMETER("j")
System returns:
Tim
Redirect(S1)
Redirects the recipient’s browser to the specified URL.
Arguments
• S1 The URL to which to redirect
Example
When inserted into a landing page, the code below redirects the browser to example.com.
%%=Redirect("http://example.com")=%%
RequestParameter(P1)
Returns the value of a parameter passed into the query string of a landing page URL.
Arguments
• P1 The parameter from which the value is requested
Example
RequestParameter(“ProductID”)
System returns the value of ProductID after it has been passed into the query string of the landing page
URL.
GetPublishedSocialContent(S1)
Returns content to be shared on a social network as specified by the region ID. This function is for use only
in landing pages or the Social Forward feature.
Arguments
• S1 The region ID for the social content area
GetPublishedSocialContent("SocialRegion1")
GetSocialPublishURL(N1,S1,S2,S3...Sn)
Retrieves the URL of a social network from a lookup table and creates a link to that social network for use
with content to be shared from an email. The optional pairs of parameters refers to additional information
like ShareThis ID numbers and logins. For use with the Social Forward feature of the ExactTarget
application.
Arguments
• N1 The number of the social network on the lookup table
• S1 The name of the content area to be shared to the social network
• S2 The name of the optional parameter
• S3 The value of the optional parameter
Example
In the pasted HTML code below, the GetSocialPublishURL() function creates a link to Facebook in order to
share the specified content area on that network.
<tablewidth="100%"bgcolor="#FFFFFF"border="0"bordercolor=""cellpadding="5"cellspa
<tr>
<tdstyle="font-family:Arial; font-size:13px">
<imgsrc="http://example.com/images/logo.jpg"
title="logo"align="left"border="0"/>
<p id="text-placeholder"style="margin-top: 0px;
margin-bottom: 0px;">This is an example of a shared content area!
Please feel free to pass on this information!<br/>
<br/></p>
<!-- Creates a link to share this content with
facebook -->
<a href="%%=GetSocialPublishURL('1','Shared content
region 1')=%%"
alias="Social Forward to Facebook"
title="Publish to Facebook">
<img src="http://images.dev2.et.local/lib/ffcf14/m/1/
GetSocialPublishURLByName(S1,S2,S3,S4,S5...Sn)
Returns the URL to the publish content page, including a site name, country code, a region ID, and optional
pairs of parameter information, such as ShareThis ID information. For use with the Social Forward feature
of the ExactTarget application.
Arguments
• S1 The name of the social network to which to share the information
• S2 The applicable country code for the social network, as defined by the ISO
• S3 The region ID of the content being shared to the social network
• S4 The name of the optional parameter
• S5 The value of the optional parameter
Example
<tablewidth="100%"bgcolor="#FFFFFF"border="0"bordercolor=""cellpadding="5"cellspa
<tr>
<tdstyle="font-family:Arial; font-size:13px">
<imgsrc="http://example.com/images/logo.jpg"
title="logo"align="left"border="0"/>
<p id="text-placeholder"style="margin-top: 0px;
margin-bottom: 0px;">This is an example of a shared content area!
Please feel free to pass on this information!<br/>
<br/></p>
<!-- Creates a link to share this content with facebook
-->
<a
href="%%=GetSocialPublishURLByName('Facebook','US','Shared content region
1')=%%" alias="Social Forward to Facebook" title="Publish to Facebook">
<img src="http://images.dev2.et.local/lib/ffcf14/m/1/
social_default_facebook_icon.jpg" alt="Facebook" title="Facebook"
border="0"></a>
</td>
</tr>
</table>
<!-- RegionEnd[ name:"Shared content region 1"] -->
Add(N1,N2)
Returns the sum of N1 and N2.
Arguments
• N1 First value to add
• N2 Second value to add
Example
Given @abc=10 and @def=20
%%=Add(@abc,@def)=%%
30
AttributeValue(S1)
Returns the value of a subscriber attribute.
Arguments
• S1 The name of the attribute to be returned
Example
Combined with a Lookup call to get the name of an attribute, you can retrieve an attribute's value and pass
it into a variable. For example, this code retrieves the value of zipcode.
Lookup("PostalCode","zipcode","PostalCode",Indianapolis)
SET @AttributeValue = AttributeValue(@AttributeName)
Base64Decode(S1,S2)
Decodes Base64 information into human-readable text.
Arguments
• S1 The location of the Base64 text, either in a variable or a data extension field (via the Lookup()
AMPscript function)
• S2 The character type to be used in the decoding process, i.e. UTF-8, UTF-16 or other .NET-
supported character type (Optional)
• B1 Indicates whether the email send proceeds if the value of S1 is incorrectly coded. Valid values
include the following:
◦ 0 - The send proceeds even if that send encounters an error
◦ 1 - The send fails if it encounters an error and no message goes out (this is the default
behavior if not specified)
Example
%%[
VAR @encodedStr, @decodedStr
SET @encodedStr = Lookup("Base64Info", "ReceiptData", "ReceiptKey", 1)
SET @decodedStr = Base64Decode(@encodedStr,"UTF-8")
]%%
The Lookup() function retrieves the Base64 information from the data extension, and the Base64Decode()
decodes the Base64 information and assigns that value to the @decodedStr variable in UTF-8 format. If for
some reason the value of @encodedStr is incorrect, the 1 at the end of the Base64Decode() function causes
the send to fail due to the error.
%%[
VAR @encodedStr, @decodedStr
SET @encodedStr = Lookup("Base64Info", "ReceiptData", "ReceiptKey", 0)
SET @decodedStr = Base64Decode(@encodedStr,"UTF-8", 1)
]%%
If the value was 0, the send would continue and the email would contain an empty string instead of the
decoded data.
Base64Encode(S1)
Encodes human-readable text into Base64 information.
Arguments
• S1 The location of the text to be encrypted, either in a variable or a data extension field (via
the Lookup() AMPscript function)
%%[
VAR @normalStr, @encodedStr
SET @normalStr = Lookup("ForBase64Info", "ReceiptData", "ReceiptKey", 1)
SET @encodedStr = Base64Encode(@normalStr)
]%%
The Lookup() function retrieves the text information from the data extension, and the Base64Encode()
encodes the text into Base64 information and assigns that value to the @encodedStr variable.
Char(S1,S2)
Returns the ASCII character specified by the ASCII character code in the first parameter. An optional
second parameter specifies the number of times to repeat the return of the ASCII character.
Arguments
• S1 Character Code
• S2 Number of times to repeat the ASCII character (Optional)
Example
Given the function below:
Char(65)
Char(65,3)
AAA
%%=CHAR(65)=%%%%=CHAR(66)=%%%%=CHAR(67)=%%
ABC
The code sample below pulls content from a data extension and replaces and carriage return-line feed
combinations with an HTML <br> tag.
%%[
/* This will pull the content out of the DE and replace any CR-LF's with
HTML BR tags. */
]%%
%%=V(@content)=%%
%%=V(@replacedContent)=%%
Concat(S1,S2,...Sn)
Concatenates the strings specified in the arguments.
Arguments
• S1-Sn Strings to concatenate
Example
%%=Concat("a","b","c")=%%
abc
This function treats Salt and IV values (either directly provided or looked up by key) as hex strings, with
each pair of characters repesenting a single byte in the larger strings. Do not attempt to use these values as
a cipher string, as you cannot successfully decrypt those strings use this function.
Divide(N1, N2)
Returns the result (quotient) of dividing the first argument by the second argument.
%%=Divide(@abc,@def)=%%
20
Domain(S1)
Returns the domain portion of an email address.
Arguments
• S1 Email address
Example
%%=Domain(sales@example.com)=%%
example.com
EncryptSymmetric(S1, S2, S3, S4, S5, S6, S7, S8, S9, S10)
Encrypts plain text data using the supplied algorithm and encryption values. You can supply either a value
or a valid external key for the password, initialization vector, and Salt. You can also use the external keys
if you have previously created keys in the Key Management section of the user interface. Otherwise, the
function generates a password using the password parameter or stored value, the Salt parameter or stored
value, and the IV parameter or stored value. If you do not pass or reference an initialization vector, the
function uses the password parameter or stored value as the initialization vector. All output provided by
this function uses base 64 encoding.
This function treats Salt and IV values (either directly provided or looked up by key) as hex strings, with
each pair of characters repesenting a single byte in the larger strings. Do not attempt to use these values as
a cipher string, as you cannot successfully encrypt those strings use this function.
Arguments
• S1 Plain text data passed to the function
• S2 Algorithm used to encrypt the data:
◦ aes - AES algorithm
◦ des - DES algorithm
◦ tripledes - TripleDES algorithm
▪ Mode (Optional, for use with DES and TripleDES only):
▪ cbc (default)
▪ ecb
▪ ofb
▪ cfb
▪ cts
▪ Padding (Optional, for use with DES and TripleDES only):
▪ none
▪ pkcs7 (default)
▪ zeros
▪ ansix923
▪ iso10126
• S3 Password external key
• S4 Password
• S5 Salt external key
• S6 Salt
• S7 Initialization vector external key
• S8 Initialization vector
Example
The example below sets the @encData variable to the encrypted value of the plain text supplied in the
function (in this case, the word Example). TThis example uses provided values for the password, salt, and
IV, and it sets any external key values to the undeclared variable @null. Note that the Salt and IV values
provided in the example below represent hex string values - the Salt value includes 8 bytes of information,
and the IV value provides 16 bytes.
Empty (V1)
Returns True if the value is the empty string or NULL.
Arguments
• V1 Variable to evaluate
%%=Empty(@abc)=%%
False
Arguments
• V1 Variable to format
• S1 A C# compatible format string. Valid values include:
◦ MM/dd/yyyy
◦ Cn (currency format where n represents the number of decimal places)
There are multiple possibilities for displaying the date using this function. For a more complete list, see
the Microsoft help regarding the DateTimeFormatInfo Class.
For more information on formatting numeric strings, see the Microsoft help regarding the
NumberFormatInfoClass.
Example 1
%%=Format(Now(),"MM/dd/yyyy")=%%
Example 2
%%=Format(@currency_variable,"$#,#.00;-$#,#.00")=%%
GUID()
Returns a new GUID as a string value.
Example
var @myGUID
set @myGUID = GUID()
The system created the @myGUID variable and sets the value of that variable with the string generated by
GUID().
IIf(E1,S1,S2)
Returns the second parameter if the first parameter evaluates True. Returns the third parameter if the
first parameter evaluates False.
Arguments
• E1 Expression to evaluate
• S1 Value to return if the expression evaluates TRUE
• S2 Value to return if the expression evaluates FALSE
Example
%%=IIF(EMPTY(@VAR),"123",@VAR)=%%
The system returns the value 123 if the @VAR variable is empty and returns the value of @VAR if it exists.
IndexOf(V1, S1)
Returns character position where string occurs in the variable. Index numbering begins with 1.
Arguments
• V1 Variable to analyze
• S1 Value whose character position to return
Example
Given @abc=You will love our product.
%%=IndexOf(@abc,"love")=%%
System returns:
10
%%[
var @abc
Set @abc = "ab"
var @index
Set @index = IndexOf(@abc,"a")
Output(v(@index))
]%%
IsEmailAddress(S1)
Returns a true or false result indicating whether the string value passed in is a valid email address. This
function uses the same email validation logic as the rest of the application.
Arguments
• S1 The email address to be validated
IsEmailAddress("joe@example.com")
IsNull(P1)
Returns a true value if the specified parameter is null.
Arguments
• P1 Parameter to check for null value
Example
Given @Row is null
IsNull(@Row)
System returns:
true
IsPhoneNumber(P1)
Returns a true or false result indicating whether the string value passed in is a valid phone number. This
function uses the same phone number validation as the SMS components of the application.
Argument
• P1 The phone number to be validated
Example
If the phone number 555-555-5555 is valid, then the function listed below will return a "true" value.
Otherwise, the function below returns a "false" value.
IsPhoneNumber("5555555555")
Length(V1)
Returns the character length of the string you specify.
Arguments
• V1 Variable whose characters to count
Example
Given @abc=Hello world!
%%=Length(@abc)=%%
System returns:
12
Lowercase(S1)
Returns the specified value in all lowercase letters.
Arguments
• S1 Value to return in lowercase letters
Example
Given @name=MARY KAY
%%=Lowercase(@name)=%%
System returns:
mary kay
MD5(S1,S2)
Converts a string to a 16-byte MD5 hash value. This function returns a hex representation of the 16-byte
MD5 hash result. This is a one-way hash conversion and does not allow later decryption.
Arguments
• S1 The string to convert to a hex representation of the 16-byte MD5 hash result
• S2 (Optional) The character set to use for the encoding; this function defaults to UTC-8 if not
specified. You can also specify UTC-16.
Example
MD5("This is a string.")
Mod(N1, N2)
Returns the remainder after dividing the first number by the second number.
Arguments
• N1 Value to be divided—the dividend
• N2 The value to divide by—the divisor
Example
%%=Mod(@abc,@def)=%%
System returns:
Multiply(N1, N2)
Returns the product of multiplying two numbers.
Arguments
• N1 A factor to be multiplied
• N2 A factor to be multiplied
Example
Given @abc=10 and @def=5
%%=Multiply(@abc,@def)=%%
System returns:
50
Output(C1)
Returns the results of AMPscript code executed within a code block and includes the results inside the
rendered content. The function does not return any passed direct literals.
Arguments
• V1 The code that produces the results to be output by the system
Example
System outputs:
My output is a success!
OutputLine(C1)
Returns the results of AMPscript code executed within a code block and includes the results inside the
rendered content. This function also appends a CRLF following the results. The function does not return
any passed direct literals.
System outputs:
My output is a success!
Note that the system outputs the CRLF after the string of text.
ProperCase(S1)
Returns specified string with initial letter of each word capitalized.
Arguments
• S1 String to return with initial capitalization
Example
Given @name=mary kay
%%=ProperCase(@name)=%%
System returns:
Mary Kay
Random(I1, I2)
Returns a random integer between the values you specify (inclusive).
Arguments
• I1 The least value the returned random integer can be
• I2 The greatest value the returned random integer can be
Example
Given @low=2 and @high=200
%%=Random(@low,@high)=%%
System returns a random value greater than or equal to 2 and less than or equal to 200.
RegExMatch(S1,S2,S3,S4...Sn)
Allows you to use a regular expression to search for information in a string.
Example
The sample AMPscript below shows how to assign regular expressions and use the RegExMatch function to
search a string for results.
%%[
VAR @sourceStr, @regEx1, @regEx2
By Group ID:
Group 1: %%=RegExMatch(@sourceStr, @regEx1, 1)=%%
Group 2: %%=RegExMatch(@sourceStr, @regEx1, "2")=%%
By Group Name:
First Number: %%=RegExMatch(@sourceStr, @regEx2, "FirstNumber")=%%
Second Number: %%=RegExMatch(@sourceStr, @regEx2, "SecondNumber")=%%
%%[
/* Check for possible match. */
VAR @result
SET @result = RegExMatch("ABC_dEF_GHI", ".*_(D..)_.*", 0, "IgnoreCase",
"Multiline")
IF Length(@result) > 0 THEN]%%
Matched!
%%[ ELSE ]%%
No match...
%%[ ENDIF ]%%
%%=Replace(@name,"2007","2008")=%%
System returns:
Arguments
• S1 String value to search
• S2 Replacement string
• S3…Sn String values to be replaced with the value in S2
Example
System returns:
XBXDXFX
SHA256(S1,S2)
Returns an SHA256 hash tag based on the string value passed through the function.
Arguments
• S1 The alphanumeric string on which the SHA256 hash tag is based
• S2 (Optional) The character set to use for the encoding; this function defaults to UTF-8 if not
specified. You can also specify UTF-16.
Example
The above function returns a hash tag in UTF-16 format based off of the text string "Insert Text Here."
SHA512(S1,S2)
Returns an SHA512 hash tag based on the string value passed through the function.
The above function returns a hash tag in UTF-16 format based off of the text string "Insert Text Here."
StringToDate(S1,S2)
Parses a datetime string with the user's current settings and returns a .NET datetime object.
Arguments
• S1 String to be parsed
• S2 (Optional) The character set to use for the encoding; this function defaults to UTC-8 if not
specified. You can also specify UTC-16.
Example
System returns a datetime object with a value of 8am on October 31st, 2009.
StringToHex(S1,S2)
Returns the hex string of bytes that make up a string value.
Arguments
• S1 The string to be encoded
• S2 (Optional) The character set to use for the encoding; this function defaults to UTC-8 if not
specified. You can also specify UTC-16.
Example
StringToHex("This is a string.")
Arguments
• S1 The string from which to return a portion
• I1 The character position at which to begin the substring
• I2 Maximum length of the substring
%%=Substring("abcdef",2,2)=%%
System returns:
bc
Subtract(N1, N2)
Returns the difference of two integers.
Arguments
• N1 Number from which to subtract N2
• N2 Number to subtract from N1
Example
Given @abc=20 and @def=5
%%=Subtract(@abc,@def)=%%
System returns:
15
Trim(S1)
Returns the value of the string parameter with the leading and trailing white space removed.
Arguments
• S1 String from which to trim white space
Example
System returns:
Text
Uppercase (S1)
Returns the specified value in all uppercase letters.
Arguments
• S1 Value to return in uppercase letters
Example
Given @name=mary kay
%%=Uppercase(@name)=%%
System returns:
MARY KAY
V(S1)
Outputs the value of a variable.
Arguments
• S1 Name of the variable whose value to return
Example
%%[
Var @var1
Set @var1="Hello"
]%%
<p>%%=v(@var1)=%%</p>
System returns:
Hello
Prerequisites
In order to use the information in this guide, you should understand basic information related to general
logic and AMPscript in specific. AMPscript is not a full-fledged object-oriented programming language like
C++, C#, or Java, but you do need to be familiar with some programming concepts to make full use of
AMPscript's features. Read over these prerequisites to familiarize yourself with the knowledge you'll need
to proceed with this guide.
AMPscript Prerequisites
Scenario
Northern Trail Outfitters maintains a monthly newsletter distributed to previous customers. Their mailing
list contains the following information on these customers:
• ZIP Code
• Email Address
• Preferences
The monthly newsletter contains updates about the company as well as content tailored specifically for the
customer. As new items come in and different sales are announced, the customer receives a customized
email including content targeted to their particular interest. Links in the email send the customer to a
landing page that features items they might be interested in and incentives to encourage a purchase. The
customer can also forward these offers to their friends and family, encouraging more sales and gathering
more information about the customer for Northern Trail Outfitters to use in their marketing campaigns.
AMPscript 101-401
The following articles demonstrate with more progressively advanced AMPscript examples how to manage
the example mailing list and use it in different email sends. You can review the information in each section
and use it in your own AMPscript code.
• AMPscript 101
• AMPscript 201
• AMPscript 301
• AMPscript 401
AMPscript 101
This article demonstrates how to create variables and use them to set values in data extensions and print
those values to the screen.
AMPscript 201
This article uses an if/else statement to insert a customer's preferred name and uses AMPscript to insert
dynamic content and an estimated shipping date.
AMPscript 301
This article adds a content lookup based on a unique row in a data extension and populates multiple fields
with content based on that row. The article also uses error checking to account for any unexpected data.
AMPscript 401
This article introduces FOR loops as part of an email send. It also demonstrates how to use AMPscript to
change the appearance of an email send, filter message context, and create content from blocks of code.
AMPscript 101
This scenario includes information on the following aspects of using AMPscript:
%%[
/* 101 */ Var @memid, @fname, @lname, @prefname, @address, @zip,
@mempref, @plat
Set @memid = MemberID
Set @fname = FirstName
Set @lname = LastName
Set @prefname = PrefName
Set @address = Address
Set @zip = Zip
Set @mempref = MemPref
Set @plat = Plat
/* 101 */
]%%%%= v(@fname) =%%, below are your account details
First Name:%%= v(@fname) =%%Last Name:%%= v(@lname) =%%
Preferred Name:%%= v(@prefname) =%% Address Address:%%= v(@address) =%%
Zip:%%= v(@zip) =%% Member Preferences Shopping Preference:%%=
v(@mempref) =%%
Platinum Member:%%= v(@plat) =%%
Note how a code block declaration sets off the first part of the AMPscript - %%[ and ]%% - because that
AMPscript spans over several lines (located between the "/* 101 */" comments). The subscriber does not
see the results of these variables yet. The Var command creates the variables named in that line of code,
each of which is separated by a comma. The Set commands give the variables the value of the information
taken from a column in the data extension associated with the send.
%%[
/* 101 */ Var @memid, @fname, @lname, @prefname, @address, @zip,
@mempref, @plat
Set @memid = MemberID
Set @fname = FirstName
Set @lname = LastName
Set @prefname = PrefName
Set @address = Address
Set @zip = Zip
Set @mempref = MemPref
Set @plat = Plat
/* 101 */
]%%
Inline code declarations set off the AMPscript within the email text - %%= and =%% - because the
AMPscript refers to a variable that belongs to a single line of text within the email. In the email,
information from the data extension associated with the email send replaces the AMPscript declarations.
From here, you cut-and-paste the AMPscript into a content area, as shown below:
To test your email with the data extension you use for the actual send, click Send Preview and select the
data extension from your available send options, as shown in the figure below:
Choose a test recipient to start your preview with and click the Generate Preview button. You will see the
information the AMPscript has pulled from the data extension placed into the email, as shown below:
Click the arrow keys in the top-right section of the screen to cycle through the other rows in the data
extension. You will see the fields change depending on the row selected. Once you are satisfied with the
information, you can send the email job. Each email you send will be populated with information from the
row associated with that subscriber.
AMPscript 201
This scenario contains information on the following aspects of using AMPscript:
%%[/* 201 */
Var @memid, @fname, @lname, @prefname, @address, @city, @state, @zip,
Member Preferences
This code is quite similar to the example shown in AMPscript 101, but notice a few important differences
that add more functionality to the email sends.
The Lookup() function consults the ShipTimes data extension and looks for the city and state that
correspond with the ZIP code value contained in the @zip variable. The function then assigns the
applicable city or state to the variable.
Preferred Name If/Else Statement
The Preferred Name field involves two different if/else statements. The first statement determines
whether or not the field is shown at all in the email. If there is no preferred name, the field is not included
in the message. If there is a preferred name, both the field and the preferred name are included in the
email.
In the section of AMPscript shown below, the ExactTarget application will insert a subscriber's preferred
name from the sendable data extension if one is available. If one is not available, then the application
defaults to the customer's first name. The if statement looks for the preferred name and inserts it if it finds
one. If not, the else statement puts in the first name.
In the case of Christa Hirsch, the email send refers to the data extension shown above and inserts the
preferred name of Chris into the email greeting.
In the case of Shea Winslow, the email greeting defaults to the first name because no preferred name is
available.
In the screenshots displayed above, the email sent to Shea Winslow shows the link because she is not a
Platinum member. The email sent to Christa Hirsch displays a Y in that field because she is a Platinum
member.
AMPscript 301
This scenario includes information on the following aspects of using AMPscript:
%%[/* 301 */
/* 301 */ ]%%
/* Set the row - This now exposes all columns to our variable */
Set @row = Row(@rows,1)
endif
endif ]%%
<tr>
<td height="30"><font size="2">State: <strong style="color:
#000;">%%= v(@state) =%%</strong></font></td>
<td height="30"><font size="2">Zip: <strong style="color:
#000;">%%= v(@zip) =%%</strong></font></td>
</tr>
<tr>
<td height="30"><font size="2">
%%[ /* We found a record for the zip code */
%%[ /* We either didn't have a zip code or couldn't find one, prompt for
profile update */
else ]%%
</table>
</div>
The majority of this AMPscript code is similar to the code present in AMPscript 201, but one new section
helps the AMPscript detect potential errors in the data and prevent them from displaying incorrect
information. It also assists the sender by prompting the subscriber to visit their online profile to update
any incorrect or missing ZIP code information.
The code just below the Address field takes the @zip variable and follows the code to insert the correct
information. It refers to the ShipTimes data extension, and the function looks for one row with the "zip"
value that matches the value contained in the @zip variable.
There should be only one row with that ZIP code value, so this code only goes into effect if the
RowCount()function finds a value of 1:
if RowCount(@rows) == 1 then
If only one row is found, the code chooses that row to take data from:
Once the row is locked in, the code uses the Field() function to assign values to the @city, @state, and @zip
variables:
If there is a ship time value available, that value appears in the email send as well:
Note that one final if/else statement determines whether the word "day" or "days" is included as
appropriate to the number value in the @ship variable.
AMPscript 401
This scenario includes information on the following aspects of using AMPscript:
%%[/* 401 */
/* Set the row - This now exposes all columns to our variable */
Set @row = Row(@rows,1)
endif
Shipping Time:%%= v(@ship) =%% %%[ if @ship > 1 then ]%%days%%[ else
]%%day%%[ endif ]%%
%%[ /* We either didn't have a zip code or couldn't find one, prompt for
profile update */
else ]%%
Member Preferences
%%[ /* Declare more variables that will be used specifically for our
products */
/* Find all the recent purchases for the subscriber we are processing */
set @rows = LookupRows("Purchases","MemberID",@memID)
/* Make sure we've found some rows before we show any purchase
information */
if RowCount(@rows) >= 1 then ]%%Recent Purchases
%%[ /* Now that we've found some data we can do something with it */
for @i = 1 to RowCount(@rows) do
contents\101-401\RecentPurchases")) =%%
%%[ /* Find out if there are two characters after the decimal point */
Set @decimalChar =
Subtract(Length(@totalPurchases),IndexOf(@totalPurchases,"."))
if @decimalChar == 1 then
The first part of the code is the same as the code found in AMPscript 301, but the second part inserts
information about a subscriber's past purchases and total amount spent into the email. First, the code
creates a new set of variables to use in inserting product and price information into the email:
%%[ /* Declare more variables that will be used specifically for our
products */
Var @prodID, @prodName, @prodDesc, @price, @indicator, @color,
@totalPurchases, @decimalChar
Next, the @totalPurchases and @indicator variables are given values. The code uses @totalPurchases to
store the subscriber's total purchases in dollar value, and it uses @indicator to alternate the background
color for each individual purchase:
Once the variables receive their initial values, the code consults the Purchases data extension to find any
previous purchases from a subscriber based on a member ID.
/* Find all the recent purchases for the subscriber we are processing */
set @rows = LookupRows("Purchases","MemberID",@memID)
If any rows are found in the data extension, the code uses the following for loop to check each row found:
/* Make sure we've found some rows before we show any purchase
information */
if RowCount(@rows) >= 1 then ]%%Recent Purchases
%%[ /* Now that we've found some data we can do something with it */
for @i = 1 to RowCount(@rows) do
As long as there is a row that matches the for loop's condition, the code will perform the following actions.
First, the code assigns values to some of the variables declared earlier. The Field() function sets values for
the fields in that specific location, and the Add() function adds the price of the individual item to the
@totalPurchase running total.
The code also sets the background color to white or gray, depending on what the previous entry's
background color was. Odd number entries get a background color of white, while even entries get a gray
background color.
Finally, the code takes the information and formats it in the same manner as the content block referred to
in the folder location in quotation marks. It then goes to the next row. If all of the rows have been used,
the code moves on to calculating the total purchases.
The final part of the code makes sure that there is a zero after a single digit decimal point value in
@totalPurchase or two zeroes after a whole number value in @totalPurchase. It also prints the
@totalPurchase value in the appropriate field.
%%[ /* Find out if there are two characters after the decimal point */
Set @decimalChar =
Subtract(Length(@totalPurchases),IndexOf(@totalPurchases,"."))
Scenarios
This document contains scenario information that demonstrates the use of AMPscript and functions.
Scenarios 122
AMPscript Guide
The marketer creates a webpage (such as a Web Collect or a Smart Capture form) where subscribers
indicate their preferred music genres. The preferences are stored in the Customer_Genre_Preferences data
extension.
Customer ID Genre
201 Rock
201 Indie
202 Pop
202 Folk
202 Rock
AMPscript
The following AMPscript appears in the body of the email.
<html>
<body style="font-size: 12px;color: #000099; font-family: verdana;">
%%[
/* First we want to determine if the customer has any favorite genres
stored. If not, we want to encourage them to create online */
%%[
if ROWCOUNT(@rsgenre) == 0 then
]%%
<h4>We see that you don't have any genres stored, please add them online
to get the most relevant information sent to you next time!</h4>
<a href="http://music.example.com">Add My Genres</a>
%%[
else
/* Now we are going to loop through each customer's genre, and then use
that and City to look up upcoming shows to display in a table */
/* if we find a genre, but no corresponding shows, we are not going to
display anything for that genre */
]%%
%%[
for @countergenre = 1 to ROWCOUNT(@rsgenre) do
<td>Tickets</td>
<td>City</td>
</tr>
%%[
for @countershow = 1 to ROWCOUNT(@rsshow) do
SET @rowshow = ROW(@rsshow, @countershow)
%%[else]%%
<tr>
%%[endif]%%
%%[
next @countershow
]%%
</table>
<br><br>
%%[
endif
]%%
%%[
next @countergenre
]%%
%%[
endif
]%%
</body>
</html>
Output
When the marketer sends the email, the application processes the code:
Hi Angel,
We want to tell you about upcoming shows in your area based on your favorite music genres. We think you
are as stoked as we are to see great live music and wanted to pass the word on. Enjoy!
From $35.00
Sat, Oct 27 Band A Venue A Indianapolis
to $45.00
From $25.00
Tue, Oct 30 Band R Venue R Indianapolis
to $35.00
From $25.00
Sat, Oct 27 Band 7 Venue 7 Indianapolis
to $40.00
From $35.00
Tue, Nov 6 Band 11 Venue 11 Indianapolis
to $50.00
From $25 to
Sat, Oct 27 Band D Venue D Indianapolis
$47.50
From $15.00
Thu, Nov 15 Band I Venue I Indianapolis
to $30.00
From $25.00
Tue, Nov 6 Band O Venue O Indianapolis
to $40.00
From $35.00
Fri, Nov 2 Band U Venue U Indianapolis
to $57.50
From $35.00
Fri, Nov 2 Band G Venue G Indianapolis
to $57.50
From $25.00
Sat, Oct 27 Band J Venue J Indianapolis
to $35.00
From $15.00
Fri, Oct 19 Band M Venue M Indianapolis
to $30.00
From $15.00
Mon, Oct 29 Band 3 Venue 3 Indianapolis
to $37.50
Hi John,
We want to tell you about upcoming shows in your area based on your favorite music genres. We think you
are as stoked as we are to see great live music and wanted to pass the word on. Enjoy!
From $35.00
Fri, Oct 19 Band 0 Venue 0 Chicago
to $57.50
From $25.00
Tue, Nov 6 Band H Venue H Chicago
to $35.00
From $15.00
Sat, Oct 27 Band L Venue L Chicago
to $37.50
From $25.00
Tue, Oct 30 Band R Venue R Chicago
to $35.00
From $25.00
Sat, Oct 27 Band 7 Venue 7 Chicago
to $40.00
From $35.00
Tue, Nov 6 Band 11 Venue 11 Chicago
to $50.00
The car broker creates an attribute for the subscriber to contain the subscriber's preference in car type.
The broker populates the attribute with a survey.
AMPscript
The car broker includes the following AMPscript block in the body of the email:
<html>
...
<table style= "border: 1px solid black">
%%[ /* Starting AMPscript */
/* Declaring variables */
</html>
Output
When the car broker sends the email, the application processes the code:
Company A Sedan A
Company B Sedan B
Company C Sedan C
Company Convertible
D A
Company Convertible
E B
Company F SUV A
Company D SUV B
Company G SUV C
Company H SUV D
Personalization strings that appear in AMPscript function calls cannot include the surrounding percent
symbols. For example, this code in AMPscript is invalid:
%%=UPPERCASE(%%emailaddr%%)=%%
%%=UPPERCASE(emailaddr)=%%
This section lists the system personalization strings (in the past referred to as system data substitution
strings) that you can insert into your email. You can type these fields directly into the HTML of your email
body if you are creating an HTML paste email, or you can type them directly into the text editor of the
Content-Building Wizard when you create or modify the text of a content box.
• When working with personalization strings inside an AMPscript block, do not use the two sets of
double percent symbols. A personalization string within an AMPscript might look like this:
fullname
additionalinfo_
This is populated only if a specific feature is enabled (Event ID functionality). It is a way to perform a send
level substitution that the declared substitution value gets applied across all emails for that particular
send. When an additionalinfo_ system personalization string is found, that string is replaced with the
value that was declared at send.
comment_ or comment
System default user-defined profile attribute.
emailaddr
Subscriber’s email address.
_EmailID
The email ID. This ID number is assigned by the system.
emailname_
Name of the email send.
firstname_ or firstname
First part of the fullname attribute subscriber or the first name.
ftaf_url
Forward to a Friend URL personalization string.
fullname_ or fullname
System default Full Name profile attribute.
_ImpressionRegionID
Returns the active region ID or 0 if none is active.
_ImpressionRegionName
Resolves to the currently active impression region or evaluates to an empty string if no impression region
has been set.
_IsTestSend
Resolves to True if the email job is marked as a Test Send.
%%[
if _isTestSend == false then
... // this code will not run for test sends
endif
]%%
jobid
Email or SMS send ID (the unique identifier associated with this send of the email, for tracking purposes).
_JobSubscriberBatchID
This value ties a Triggered Send Job or a Subscriber Key Send Job to a Subscriber to a Batch ID.
In triggered sends, for one Job ID there are potentially multiple sends to a subscriber, so you can't count on
the combination to be unique. By adding the BatchID, there is enough information to correlate clicks,
bounces, opens, and unsubscribes back to the original send.
The other place that JobSubscriberBatch could be used is in Subscriber Key based sends. If a send contains
duplicate email addresses, each email address will have a different Job Subscriber Batch.
By default, JobSubscriberBatch is 0.
lastname_ or lastname
Last name of the subscriber.
list_
listid
ExactTarget list ID (for example, 1234).
_ListName
The name of the list. This is the name you provide when you create the list.
listsubid
Rarely used. ID number associated with subscriber’s membership to a list.
member_addr
CAN-SPAM business address.
member_busname
CAN-SPAM business name.
member_city
CAN-SPAM business city.
member_country
CAN-SPAM business country.
memberid
ExactTarget Account ID.
member_postalcode
CAN-SPAM business postal code.
member_state
CAN-SPAM business state.
_messagecontext
Provides a way to display different content based on the channel (browser, email client, etc.) in which the
content is viewed. For example, if content is being viewed through a browser in a landing page, that
content can be more robust and formatted differently because you are not constrained to an email client.
Possible message context values include:
• FTAF
• LANDINGPAGE
• LINKRESOLUTION
• PLATFORM
• PREVIEW
• SEND
• SMS
• SOCIAL
• VALIDATION
• VAWP
• VIEWSENT
_messagetypepreference
Resolves to text or to HTML, according to the subscriber’s email type preference.
_replycontent
Used in triggered sends to place the body of an email into a reply email.
profile_center_url
Profile Center URL personalization string.
replyname
Reply name for the email send.
replyemailaddress
Reply email address for the email send.
subscriberid
An ExactTarget-defined unique identifier for each subscriber.
_subscriberkey
Used as a unique identifier of the subscriber.
subscription_center_url
Subscription Center URL personalization string.
unsub_center_url
Unsub Center URL personalization string.
xtday
Day when the email is sent (for example, 22).
xtdayofweek
Day when the email is sent (for example, Thursday).
xtlongdate
Date when the email is sent in long format—for example, Monday, August 11, 2008.
xtmonth
Full name of the month during which the email is sent.
xtmonthnumeric
Current month (as number).
xtshortdate
Date when the email is sent in short format—for example, 8/11/2008.
xtyear
Year when the email is sent.
view_email_url
View as webpage URL personalization string.
_CarrierID
Carrier ID associated with the Contact, contained in the Contact's CarrierID field.
_Channel
Channel associated with the Contact, contained in the Contact's Channel field.
_City
City associated with the Contact, contained in the Contact's City field.
_ContactID
Contact ID associated with the Contact, contained in the Contact's ContactID field.
_CountryCode
Country code associated with the Contact, contained in the Contact's CountryCode field.
_CreatedBy
The entity that created the Contact, contained in the Contact's CreatedBy field.
_CreatedDate
The date on which the Contact was created, contained in the Contact's CreatedDate field.
_FirstName
The Contact's first name, contained in the FirstName field.
_IsHonorDST
Indicates whether the Contact's time zone honors Daylight Savings Time, contained in
the Contact's IsHonorDST field.
_LastName
The Contact's last name, contained in the Contact's LastName field.
_MobileNumber
The Contact's mobile number, contained in the Contact's MobileNumber field.
_ModifiedBy
The last user to modify a Contact's information, contained in the Contact's ModifiedBy field.
_ModifiedDate
The last time a process modified a Contact's information, contained in the Contact's ModifiedDate field.
_Priority
The priority to use when sending a message to a Contact, contained in the Contact's Priority field.
_Source
The source of a Contact's information, contained in the Contact's Source field.
_SourceObjectID
The object ID of the source of a Contact's information, contained in the Contact's SourceObjectID field.
_State
The state associated with a Contact, contained in the Contact's State field.
_Status
The send status associated with a Contact, contained in the Contact's Status field.
_UTCOffset
The time offset from UTC associated with a Contact, contained in the Contact's UTCOffset field.
_ZipCode
The ZIP code associated with a Contact, contained in the Contact's ZipCode field.