Anda di halaman 1dari 139

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

AMPscript Syntax Guide. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17


Using AMPscript Code and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Function Call Outside an AMPscript Block (Inline AMPscript) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Function Call Inside an AMPscript Block. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Function Return Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Tag-based Syntax for AMPscript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Minimum Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Full Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Delimiter Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Using Function Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
AMPscript Language Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Attribute and Data Extension (Custom Object) Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Keywords. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Using Conditions Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Using IF Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Using the IF Condition Evaluation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Using the FOR Process Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Using the SET Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Using the Output and OutputLine keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

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

AMPscript Syntax Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30


Alphabetical List of AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
AMPscript Functions for use with Microsoft Dynamics CRM . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
UpdateMscrmRecords(S1,S2,S3a,S3b...SNa,SNb) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
UpsertMscrmRecord(S1,S2,S3,S4,S5a,S5b,S6a,S6b). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
CreateMscrmRecord(S1,S2,S3a,S3b) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
RetrieveMscrmRecords(S1,S2,S3a,S3b,S3c). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
RetrieveMscrmRecordsFetchXML(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
DescribeMscrmEntities() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
DescribeMscrmEntityAttributes(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
AddMscrmListMember(S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
SetStateMscrmRecord(S1,S2,S3,S4) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Special Attribute Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Party List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

AMPScript Functions for use with Salesforce.com . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39


CreateSalesforceObject(S1,I1,S2a,S2b,...Sna,Snb). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
RetrieveSalesforceJobSources(P1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

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

Updating the Campaign Status of a Lead or Contact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42


API AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Why Use the API AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
How To Use the API AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
AddObjectArrayItem(O1,S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
CreateObject(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Field(S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
InvokeCreate(O1,S1,N1,O2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
InvokeDelete(O1,S1,N1,O2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
InvokeExecute. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
InvokePerform(O1,S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
InvokeRetrieve(P1,P2,P3). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
InvokeUpdate(P1,P2,P3,P4) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
RaiseError(S1,B1,S2,S3,B2). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
SetObjectProperty(O1,S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

4
AMPscript Guide
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

Content AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49


Why Use the Content AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
How To Use the Content AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
AttachFile(S1,S2,S3,B1,S4,S5,N1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
BarCodeURL(S1,S2,N1,N2,S3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
BeginImpressionRegion(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
BuildOptionList(S1,S2,S3). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
BuildRowSetFromString(S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
BuildRowSetFromXML(S1,S2,B1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
ContentArea(I1,S1,B1,S2,N1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
ContentAreaByName(S1,S2,B1,S3,N1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
EndImpressionRegion(B1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
GetPortfolioItem(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Image(S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Row(RS, I1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
RowCount(RS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
SetSmsConversationNextKeyword(S1,S2,S3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

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

Data Extension AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61


Why Use the Data Extension AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
How To Use the Data Extension AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Enterprise and Enterprise 2.0 Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
ClaimRow(S1,S2,S3,S4,...Sn,Sn+1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
ClaimRowValue(S1,S2,S3,S4,S5,S6,...Sn, Sn+1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
DeleteDE(S1, S2, S3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
ExecuteFilter(S1,S2,S3...). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
ExecuteFilterOrderedRows(S1,N1,S2,S3,S4...) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
InsertDE(S1, S2, S3). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Lookup(S1, S2, S3, S4). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
LookupOrderedRows(S1, N1, S2, S3, S4) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
LookupOrderedRowsCS(S1, N1, S2, S3, S4). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

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

DateTime AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71


Why Use the DateTime AMPscript Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
How To Use the DateTime AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
DateAdd(D1, I1, S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
DateDiff(D1, D2, S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
DateParse(S1,B1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
DatePart(D1, S1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
LocalDateToSystemDate(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Now(P1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
SystemDateToLocalDate(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

7
AMPscript Guide

HTTP AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73


Why Use the HTTP AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
How To Use the HTTP AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
HTTPGet(S1,B1,N1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
HTTPRequestHeader(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
RedirectTo(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
URLEncode(S1,B1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
WrapLongURL(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

Microsite and Landing Page AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76


Why Use the Microsite and Landing Page AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . 77
How To Use the Microsite and Landing Page AMPscript Functions . . . . . . . . . . . . . . . . . . . . . 77
AuthenticatedEmployeeID() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
AuthenticatedEmployeeNotificationAddress() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
AuthenticatedEmployeeUserName(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
AuthenticatedEnterpriseID() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
AuthenticatedMemberID() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
AuthenticatedMemberName() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
DeleteData(S1, S2, S3). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
InsertData(S1, S2, S3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
IsNullDefault(S1, S2). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

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

Social AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80


Why Use the Social AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
How To Use the Social AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
GetPublishedSocialContent(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
GetSocialPublishURL(N1,S1,S2,S3...Sn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
GetSocialPublishURLByName(S1,S2,S3,S4,S5...Sn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

Utilities AMPscript Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83


Why Use the Utilities AMPscript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
How To Use the Utilities AMPscript Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Add(N1,N2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
AttributeValue(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Base64Decode(S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Base64Encode(S1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Char(S1,S2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

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

Getting Started With AMPscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100


Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
AMPscript 101-401 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
AMPscript 101 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
AMPscript 201 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
AMPscript 301 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
AMPscript 401 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

AMPscript 101 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101


The AMPscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
AMPscript 201 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
The Lookup() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Preferred Name If/Else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Platinum Status If/Else Statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

AMPscript 301 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112


AMPscript 401 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Scenario 1: Concerts in Your Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Data Extensions and Relationships. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
AMPscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Upcoming Shows in Indianapolis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Upcoming Rock Shows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Upcoming Alt-Country Shows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Upcoming Indie Shows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Upcoming Shows in Chicago . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Upcoming Pop Shows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Upcoming Folk Shows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

12
AMPscript Guide
Upcoming Rock Shows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

Scenario 2: Suggested Car Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131


Data Extensions and Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
AMPscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

Using Personalization Strings with AMPscript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134


ExactTarget Personalization Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
additionalinfo_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
comment_ or comment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
emailaddr. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
_EmailID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
emailname_. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
firstname_ or firstname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
ftaf_url . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
fullname_ or fullname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
_ImpressionRegionID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
_ImpressionRegionName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
_IsTestSend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
jobid. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
_JobSubscriberBatchID. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
lastname_ or lastname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
list_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
listid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
_ListName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
listsubid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
member_addr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
member_busname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
member_city . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
member_country . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
memberid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
member_postalcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
member_state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
_messagecontext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
_messagetypepreference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
_replycontent. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
profile_center_url. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
replyname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
replyemailaddress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
subscriberid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
_subscriberkey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
subscription_center_url . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
unsub_center_url. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
xtday . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
xtdayofweek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

13
AMPscript Guide
xtlongdate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
xtmonth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
xtmonthnumeric. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
xtshortdate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
xtyear. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
view_email_url. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

Contacts Personalization Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138


_CarrierID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
_Channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
_City . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
_ContactID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
_CountryCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
_CreatedBy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
_CreatedDate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_FirstName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_IsHonorDST. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_LastName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_MobileNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_ModifiedBy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_ModifiedDate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_Priority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_SourceObjectID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_UTCOffset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
_ZipCode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

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 Syntax Guide


◦ AMPscript Functions for use with Microsoft Dynamics CRM
◦ AMPScript Functions for use with Salesforce.com
◦ API AMPscript Functions
◦ Contacts AMPscript Functions
◦ Microsite and Landing Page AMPscript Functions
◦ Content AMPscript Functions
◦ Data Extension AMPscript Functions
◦ DateTime AMPscript Functions
◦ HTTP AMPscript Functions
◦ Social AMPscript Functions
◦ Utilities AMPscript Functions
• AMPscript Variables for Use with Mobile Messages
• Getting Started with AMPscript - AMPscript 101
• Getting Started with AMPscript - AMPscript 201
• Getting Started with AMPscript - AMPscript 301
• Getting Started with AMPscript - AMPscript 401
• Scenarios Using AMPscript
• Using Personalization Strings with AMPscript

AMPscript 15
AMPscript Guide

Why Use AMPscript


Use AMPscript to process information and include information from your data extensions in the body of
your messages and landing pages to provide advanced personalization for the subscribers. You can use
AMPscript and functions to perform operations such as the following:

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.

Display Metadata about the Data


You can use a function to indicate whether a record exists for the subscriber. For example, you can use a
function to determine whether a subscriber completed a transaction in the last month.

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.

Provide Control Logic


A function can contain logic to perform different operations based on a subscriber value.

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.

Why Use AMPscript 16


AMPscript Guide

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.

AMPscript Syntax Guide


This document contains conceptual and procedural information on AMPscript syntax and usage, including
function calls, variables, values, and keywords. You can use the information in this document to correctly
form AMPscript function calls, declare variables and values, and reference AMPscript keywords.

Using AMPscript Code and Functions


You call the AMPscript at the location in the email message, landing page, or SMS message where you want
the result of the script to appear. All AMPscript code and functions must be surrounded by open and close
delimiters, or the code will be ignored by the system.

%%[script]%%

Function Call Outside an AMPscript Block (Inline AMPscript)


Function calls outside of an AMPscript block must be introduced by the opening delimiter %%= and
terminated by the closing delimiter =%%.

%%=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 Call Inside an AMPscript Block


Function calls within an AMPscript block should not include the opening (%%=) and closing (=%%)
delimiters.

%%[ LOWERCASE(Name) ]%%

AMPscript Syntax Guide 17


AMPscript Guide

Function Return Values

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))=%%

Tag-based Syntax for AMPscript


Tag-based syntax for AMPscript standardizes the syntax used to declare AMPscript blocks with the syntax
of server-side JavaScript. This syntax eases the burden on developers to write in a different syntax when
switching between AMPscript and server-side JavaScript. Use the information below to format your
AMPscript calls. The system processes AMPscript calls in a case-insensitive manner.

Minimum Syntax
This sample illustrates the minimum syntax necessary to declare an AMPscript block.

<script runat=server language=ampscript>


[INSERT AMPSCRIPT HERE]
</script>

Full Syntax
This sample illustrates the complete syntax used to declare an AMPscript block.

<script runat=server language="ampscript" executioncontexttype="Post"


executioncontextname=test>
[INSERT AMPSCRIPT HERE]
</script>

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.

Standard AMPscript Delimiter Tag-based AMPscript Delimiter

<script runat=server
%%[
language=ampscript>

<script runat=server
language=ampscript
%%[[type=post;name=blockname]
executioncontexttype="Post"
executioncontextname=blockname>

Using AMPscript Code and Functions 18


AMPscript Guide

Standard AMPscript Delimiter Tag-based AMPscript Delimiter

]%% </script>

<script runat=server
%%[]%%
language=ampscript />

Using Function Calls

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.

Function Call Outside an AMPscript Block

%%=LOWERCASE(Name)=%%

Function Call Inside an AMPscript Block

%%[ LOWERCASE(Name) ]%%

Functions Accept Any of These Input Types:

Constant Value

LOWERCASE("Mary Smith")

Attribute Value

LOWERCASE(Name)

Variable Value

LOWERCASE(@Name)

AMPscript Language Elements


AMPscript uses the following language elements:

• Constants
• Attributes and Data Extensions
• Keywords

Using AMPscript Code and Functions 19


AMPscript Guide

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.

"A string value"

"123.456"

'a string value'

'Sally"s string value'

(Doubled '' will be rendered as ')

Boolean constant values must be true or false and are case insensitive. Here are some examples:

true

false

TRUE

False

Attribute and Data Extension (Custom Object) Values


Subscriber attribute, additional email attributes, and data extension column values are referenced in
functions and scripts as unquoted strings. If the attribute, data extension column, table, or relationship
name includes a space or special character, it must be enclosed in square brackets. For example:

EmailAdr

[Data Extension Attribute Name]

[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.

Using AMPscript Code and Functions 20


AMPscript Guide

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.

Declare VAR @variable

SET <variable>=<constant function or


Set
attribute>

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]%%

%%[VAR @Count1, @Count2, @Count3]%%

Using Conditions Syntax


Use the following syntax for simple comparison:

<variable, attribute><simple operator><variable, attribute, function, constant>

Comparison operators compare values.

== Is equal to

!= Is not equal to

> Greater than

< Less Than

Using AMPscript Code and Functions 21


AMPscript Guide

Greater than or equal


>=
to

<= Less than or equal to

Join operators are used to combine multiple conditions.

AND Both conditions must be true

OR Either condition must be true

The NOT operator reverses the result of any Boolean expression.

Reverses the Boolean


NOT
expression

You can control the expression evaluation using parentheses:

(BooleanExpression AND BooleanExpression) OR (BooleanExpression AND


BooleanExpression)

Using IF Syntax

if <condition> then <statement>


elseif <condition> then <statement>

else <statement>
endif

Statements

if Use the if statement to perform conditional processing.

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.

Using AMPscript Code and Functions 22


AMPscript Guide
Using the IF Condition Evaluation
The IF statement allows the conditional execution of any content within the IF block dependent on the
evaluation of the logic expressions it contains. IF statements may be nested within IF statements. The
syntax for the IF statement follows:

%%[IF expression1 <comparison operator> expression2 THEN]%%


[wrapped script or email content]
%%[ELSEIF expression1 <comparison operator> expression3 THEN]%%
[wrapped script or email content]
%%[ELSE]%%
[wrapped script or email content]
%%[ENDIF]%%

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:

IF expression1 <comparison operator> expression2


AND [NOT] (expression3 <comparison operator> expression4
OR expression3 <comparison operator> expression5)
THEN …

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.

IF NOT EMPTY(expression1) THEN

The following example demonstrates how to include a variable if a value is present and leave that variable
out if no value is present:

%%[if not empty(MailingAddress) then]%%


%%MailingAddress%%
%%[endif]%%

Using AMPscript Code and Functions 23


AMPscript Guide
Using the FOR Process Loop
The FOR statement allows content within the FOR block to be iterated over a variable number of times.
The syntax of the FOR loop follows:

%%[FOR @Variable = <start expression> TO|DOWNTO <end expression> DO ]%%


[wrapped script or email content]
%%[NEXT @Variable]%%

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.

Using the SET Statement


Variables are assigned a value using the SET statement. Only one variable may be initialized using a SET
statement. An attempt to set a variable that is in use at the counter of a FOR loop will generate a validation
or runtime error. The variable takes on the type of the assigned value.

%%[
VAR @Count, @Count2
SET @Count = 0
SET @Count2 = 100
]%%
@Name
@C1

Using the Output and OutputLine keywords


The keywords Output and OutputLine returns the results of code executed inside a code block and includes
the results in the rendered content. The OutputLine keyword also appends a carriage return and line
feed (CRLF) to the end of the resolved content. Output and OutputLine works with the results of a nested
function or script block, and they do not support the passing of direct literals.

Given the code below:

Using AMPscript Code and Functions 24


AMPscript Guide

%%[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.

Given the code below:

%%[ Var @text


Set @text = "Example Text"
Output(v(@text)) ]%%

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:

%%[ Var @text


Set @text = "Example Text"
Output(@text) ]%%

Again, the code example above does not work because Output does not support the passing of direct
literals.

Given the function below:

%%[ OutputLine(Substring("Example Text",1,6)) ]%%

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.

%%[ /* Insert Comment Here */ ]%%

Using AMPscript Language Elements with Enterprise Awareness


The following AMPscript functions have Enterprise awareness:

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.

Using AMPscript Code and Functions 25


AMPscript Guide

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>

Using Data Modification Functions


Two sets of functions allow a client’s data extension data to be modified through AMPscript: send time
support and landing page support. These functions allow insert, update, upsert (update/insert), and
delete actions to be performed at the subscriber level. The use of these functions is restricted according to
the content being processed by the ExactTarget system.

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")=%%

Send Time Support


If an error occurs, the subscriber emails for the batch will not be sent and the job will be set to an error
status. If the sending of the batch is interrupted, these calls for the interrupted batch maybe repeated.
You should therefore write these calls in a manner that will allow them to be successfully executed
multiple times.

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

Using AMPscript Code and Functions 26


AMPscript Guide

"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")=%%

Landing Page Support


The INSERTDATA, UPDATEDATA, UPSERTDATA, and DELETEDATA functions allow data extension data to
be modified when building landing pages. This functionality is distinguished from the send time functions
in the following ways:

• 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")=%%

Using AMPscript Code and Functions 27


AMPscript Guide

Using Execution Context


Content used in landing pages, Web Collect and Smart Capture and called via an AMPScript function can be
processed contextually by the ExactTarget system. That message content is processed depending on the
context of the function’s execution.

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:

/* Content and Script to always be executed here */


%%[ IF @@ExecCtx == “LOAD” THEN]%%
%%[/*Load Content or Script Here*/]%%
%%[ ELSEIF @@ExecCtx == “POST” THEN]%%
%%[/*Load Content or Script Here*/]%%
%%[ENDIF]%%
/* Content and Script to always be executed here */

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:

“An incomplete IF statement exists in a typed script block. Script


statements cannot span named or typed script blocks.”

Using AMPscript Code and Functions 28


AMPscript Guide

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.

Using Dynamic Link Names


Dynamic link names or link aliases are supported. This functionality lets you include dynamic content,
including substitution strings and AMPscript function calls, in the name assigned to a link and then track
the link by the resolved values.

This functionality is available only if:

• You are using the HTML version of emails.


• You are using Always on Clicks.
When creating an email, include your dynamic statements when setting the link name or alias attribute in
the Content Editor inside the user interface. For example:

<a href="http://website.example.com/key/p...ID=C12915x001B" target="new"


alias="%%=CONCAT(Region,' Region')=%%">

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 and Time Formatting


You can use several different data and time formats with AMPscript, depending on your needs. The table
below demonstrates the available formats:

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)

y = 11 M=8 d = 15 h=8 m=0 s=5 t=P z = -6

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

Using AMPscript Code and Functions 29


AMPscript Guide

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)

yyyy = MMMM = dddd =


HH = 08 - - - -
2011 August Monday

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:

%%=Format(Now(), "MMMM d, yyyy")=%%


August 15, 2011

The example below takes the value of Now(), offsets it using the DateAdd() function, then returns that
value in the specified format:

%%[ VAR @futureDate, @today SET @today = Now(1) SET @futureDate =


DateAdd(@today, 11, "D") ]%%
Date: %%=Format(@futureDate, "MMMM d, yyyy")=%%

The example below outputs the Birthday attribute of a subscriber in the format specified:

%%[Output(Format([Birthday],"dd/MM/yyyy"))]%%

AMPscript Syntax Templates


You can use the files linked below to highlight AMPscript functions and variables within the Notepad++
and Ultraedit text editors. These templates also support code folding for IF statements and AMPscript
blocks. To use these templates, download the .zip files and install the templates using the instructions
found on the readme.txt files. ExactTarget does not offer support for these files.

AmpscriptSyntaxHighlighting.zip

Alphabetical List of AMPscript Functions


Use this alphabetized list of all documented AMPscript functions to find more information on a specific
function.

• Add(N1,N2)
• AddMscrmListMember(S1,S2)
• AddObjectArrayItem(O1,S1,S2)
• Arguments
• Arguments
• AttachFile(S1,S2,S3,B1,S4,S5,N1)
• AttributeValue(S1)
• AuthenticatedEmployeeID()

AMPscript Syntax Templates 30


AMPscript Guide

• 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()

Alphabetical List of AMPscript Functions 31


AMPscript Guide

• 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)

Alphabetical List of AMPscript Functions 32


AMPscript Guide

• 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)

AMPscript Functions for use with Microsoft Dynamics CRM


Users of ExactTarget for Microsoft Dynamics CRM use these AMPscript functions in conjunction with
Smart Capture and landing pages to modify records in the Microsoft Dynamics CRM system. Do not use
these functions as part of any email messages.

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

AMPscript Functions for use with Microsoft Dynamics CRM 33


AMPscript Guide

• S2 A comma-separated list of the record GUIDs to update


• S3a, S3b Name and Value parts of attributes to update on the target records
Example

%%[

/* Sample Code - this updates several lead records to have Web as a Lead
Source Code in Dynamics CRM */

var @records_updated

set @records_updated = updatemscrmrecords('lead',


'2E438216-2DEE-DD11-AB3E-005056AD58C4,0A167EEC-6436-DD11-B7BE-000E7F30252C',
'leadsourcecode', '8')

]%%

<p>Count of records updated:</p><br>

%%=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

%%[

/* Sample Code - this creates a new Contact record */

AMPscript Functions for use with Microsoft Dynamics CRM 34


AMPscript Guide

var @contact_guid

set @contact_guid = createmscrmrecord('contact', 3, 'firstname', 'bob',


'lastname', 'testcontact', 'emailaddress1', 'bob@example.com')

]%%

<p>GUID of new Contact:</p><br>

%%=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
*/

var @records_retrieved, @counter, @firstname, @lastname, @id

set @records_retrieved = retrievemscrmrecords('contact',


'contactid,firstname,lastname', 'firstname', '=', 'john')

]%%

<p>Contacts:</p><br><br>

%%[

AMPscript Functions for use with Microsoft Dynamics CRM 35


AMPscript Guide

for @counter = 1 to rowcount(@records_retrieved) do

set @firstname = field(row(@records_retrieved,@counter),'firstname')

set @lastname = field(row(@records_retrieved,@counter),'lastname')

set @id = field(row(@records_retrieved,@counter),'contactid')

]%%

<p>First: &nbsp; &nbsp; %%=v(@firstname)=%% </p>

<p>Last: &nbsp; &nbsp; %%=v(@lastname)=%% </p>

<p>Id: &nbsp; &nbsp; %%=v(@id)=%% </p> <br><br>

%%[next @counter ]%%

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

%%[

/* Sample code to get a list of all entities in a Dynamics CRM account to


a record set */

var @entities_rs

set @entities_rs = describemscrmentities()

]%%

<p> Here is a list of CRM Entities </p>

%%[

AMPscript Functions for use with Microsoft Dynamics CRM 36


AMPscript Guide

var @entity_name, @entity_displayname, @counter

for @counter = 1 to rowcount(@entities_rs) do

set @entity_name = field(row(@entities_rs,@counter), 'Name')

set @entity_displayname = field(row(@entities_rs,@counter), 'DisplayName')

]%%

Entity Name: &nbsp; &nbsp; %%=v(@entity_name)=%% <br>

Entity Display Name: &nbsp; &nbsp; %%=v(@entity_displayname)=%% <br>


<br><br>

%%[ next @counter ]%%

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

set @fields_rs = describemscrmentityattributes('lead')

]%%

<p> Here is a list of Fields in the Lead Entity </p>

%%[

var @field_name, @field_displayname, @counter, @field_type,


@field_required, @field_options

for @counter = 1 to rowcount(@fields_rs) do

set @field_name = field(row(@fields_rs,@counter), 'Name')

set @field_displayname = field(row(@fields_rs,@counter), 'DisplayName')

AMPscript Functions for use with Microsoft Dynamics CRM 37


AMPscript Guide

set @field_type = field(row(@fields_rs,@counter), 'Type')

set @field_required = field(row(@fields_rs,@counter), 'Required')

set @field_options = field(row(@fields_rs,@counter), 'Options')

]%%

Field Name: &nbsp; &nbsp; %%=v(@field_name)=%% <br>

Field Display Name: &nbsp; &nbsp; %%=v(@field_displayname)=%% <br>

Field Type: &nbsp; &nbsp; %%=v(@field_type)=%% <br>

Field Required?: &nbsp; &nbsp; %%=v(@field_required)=%% <br>

Field Options: &nbsp; &nbsp; %%=v(@field_options)=%% <br> <br><br>

%%[ next @counter ]%%

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

%%[

/* Adds a lead, contact or account to a marketing list */

var @guid, @list_guid

set @guid = '2E438216-2DEE-DD11-AB3E-005056AD58C4'

set @list_guid = '0A167EEC-6436-DD11-B7BE-000E7F30252C'

AddMscrmListMember(@guid, @list_guid)

]%%

AMPscript Functions for use with Microsoft Dynamics CRM 38


AMPscript Guide

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"

%%[

/* sample code to change the state of an account to inactive */

SetStateMscrmRecord(“00000000-0000-0000-0000-000000000001”, “account”,
“Inactive”, “-1”)

]%%

Special Attribute Types


Lookup
If the attribute specified can be related to multiple Dynamics CRM entities, you must specify the type of
entity the attribute belongs to by adding |lookup (replacing lookup with the entity). For example, the
customerid field could be related to an account or contact. If it's related to an account, specify this by
adding |account at the end of the attribute.

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).

AMPScript Functions for use with Salesforce.com

AMPScript Functions for use with Salesforce.com 39


AMPscript Guide

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

%%[ var @id


set @id=CreateSalesforceObject("lead", 2, "FirstName", "Chris",
"LastName", "Cruz")
]%%

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.

AMPScript Functions for use with Salesforce.com 40


AMPscript Guide

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.

Multiple sets of criteria are joined by an AND operator.

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

%%[ var @rs


Set @rs= RetrieveSalesforceObjects("Lead", "Id, FirstName,LastName",
"region", "=", "west")
]%%

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")=%%

AMPScript Functions for use with Salesforce.com 41


AMPscript Guide

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.

Sending an Email Message to a Salesforce Object via AMPscript


Be sure to specify the UserID of the Salesforce-integrated user along with the account ID for the send.

%%[
var @senddef, @msg, @sc
Set @senddef = CreateObject("EmailSendDefinition")
SetObjectProperty(@senddef, "CustomerKey", "SFSend")

Set @cid= CreateObject("ClientID")


SetObjectProperty(@cid, "ID", "113903")
SetObjectProperty(@cid, "UserID", "191589")

SetObjectProperty(@senddef, "Client", @cid)

Set @sc = InvokePerform(@senddef,"start",@msg)


]%%

%%=v(@sc)=%%
<br />
%%=v(@msg)=%%

Updating the Campaign Status of a Lead or Contact


The sample AMPscript below uses the RetrieveSalesforceObjects() and UpdateSingleSalesforceObject()
function in a landing page to update the campaign status of a Lead or Contact. When the Lead or Contact

Updating the Campaign Status of a Lead or Contact 42


AMPscript Guide

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.

%%[ Var @CamId, @Id, @Leads, @CamMems, @FirstName, @LastName, @Result,


@CamMemId, @LeadId, @LongId
Set @CamId = "YourCamIdHere"
Set @Id = QUERYPARAMETER("sfid")
Set @LongId = LongSFID(@Id)

Set @Leads = RetrieveSalesforceObjects("Lead", "Id, FirstName,LastName",


"Id", "=", @Id)
Set @row = ROW(@Leads,1)
Set @FirstName = FIELD(@row,"FirstName")
Set @LastName = FIELD(@row,"LastName")

Set @CamMem = RetrieveSalesforceObjects("CampaignMember", "Id,


CampaignId, LeadId, Status", "CampaignId", "=", @CamId)
For @i = 1 TO RowCount(@CamMem) DO
Set @row = ROW(@CamMem,@i)
Set @LeadId = FIELD(@row,"LeadId")
If @LeadId == @LongId Then
Set @CamMemId = FIELD(@row,"Id")
EndIf
Next @i

Set @Result =
UpdateSingleSalesforceObject("CampaignMember",@CamMemId,"Status","RSVP-Yes")
]%%

<br />
Thank you %%=v(@FirstName)=%% %%=v(@LastName)=%% for signing up for the
our webinar!

API AMPscript Functions


This document contains conceptual, procedural, and scenario information about API AMPscript functions.

Why Use the API AMPscript Functions


You can use these functions to interact with the ExactTarget web service API.

How To Use the API AMPscript Functions


Create your AMPscript using the functions below and place them in the content areas of landing
pages. These functions do not work in emails at the time of send and will cause your send to error out.

API AMPscript Functions 43


AMPscript Guide

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

SET @subscriber = CreateObject("Subscriber")

Creates a new Subscriber object for the web service API.

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.

How To Use the API AMPscript Functions 44


AMPscript Guide

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"

SET @ts = CreateObject("TriggeredSend")


SET @tsDef = CreateObject("TriggeredSendDefinition")
SET @ts_subkey = @emailaddr

SetObjectProperty(@tsDef, "CustomerKey", "VolConfirm")


SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)

SET @ts_sub = CreateObject("Subscriber")


SetObjectProperty(@ts_sub, "EmailAddress", @emailaddr)
SetObjectProperty(@ts_sub, "SubscriberKey", @ts_subkey)

AddObjectArrayItem(@ts, "Subscribers", @ts_sub)


SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)

IF @ts_statusCode != "OK" THEN


RaiseError(@ts_statusMsg, 0, @ts_statusCode, @errorCode)
ENDIF

]%%

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.

How To Use the API AMPscript Functions 45


AMPscript Guide
Arguments
• O1 The API object to be deleted
• S1 Output parameter for the API status message
• N1 Output parameter for the API error code
• O2 The DeleteOptions API call
InvokeExecute
Invokes the Execute 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:

SET @lue = CreateObject("ExecuteRequest")

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)

How To Use the API AMPscript Functions 46


AMPscript Guide

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)

SET @lue_statusCode = InvokeExecute(@lue,


@overallStatus, @requestId)

SET @Response = Row(@lue_statusCode, 1)


SET @Status =
Field(@Response,"StatusMessage")
SET @Error = Field(@Response,"ErrorCode")

IF (@Error == "12012") OR (@Error ==


"401") OR (@Status == "Event posted") THEN
/* Succeeded */
ELSE
/* Failed */
ENDIF

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

How To Use the API AMPscript Functions 47


AMPscript Guide

• S2 Output parameter that gives the API status message


InvokeRetrieve(P1,P2,P3)
Returns an array of API objects from a RetrieveRequest object.

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

RaiseError(“An Error Occurred”)

How To Use the API AMPscript Functions 48


AMPscript Guide

System returns the error message “An Error Occurred” and stops the job.

RaiseError(“Do not send to subscriber”, true)

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")

Content AMPscript Functions


This document contains conceptual, procedural, and scenario information about content AMPscript
functions.

Why Use the Content AMPscript Functions


You can use these functions to interact with the content contained in your ExactTarget account. For
example, you could use the GetContentAreaByName() function to insert the data contained within a
content area into a landing page.

Content AMPscript Functions 49


AMPscript Guide

How To Use the Content AMPscript Functions


Create your AMPscript using the functions below and place them in the content areas of email messages or
landing pages.

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:

How To Use the Content AMPscript Functions 50


AMPscript Guide

%%=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 :

• Microsoft Word documents (.doc, .docx)


• Microsoft Excel documents (.xls, .xlsx)
• Microsoft Powerpoint documents (.ppt, .pptx)
• Adobe PDF documents (.pdf)
• ZIP archive files (.zip)
• Compressed archive files (.rar)
• PNG images (.png)
• GIF images (.gif)
• JPEG images (.jpg, .jpeg)
• TIFF images (.tif, .tiff)
This function supports secure transmission over HTTPS.

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

How To Use the Content AMPscript Functions 51


AMPscript Guide

◦ 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.

How To Use the Content AMPscript Functions 52


AMPscript Guide

%%=BarCodeURL("BBY01-397101069285","Code39", 400, 200, 0, 0, "Alt Text",


90, 1)=%%

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.

%%=BarCodeURL('9X4H341ZTKTPMN7T','Code128B', 231, 55, 0, 1,'',90,1)=%%

BeginImpressionRegion(S1)
Denotes the beginning of a region to be tracked with impression tracking.

Arguments
• S1 Name of the impression region
Example

%%=BeginImpressionRegion(Header)=%%

The system begins an impression tracking region called 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

%%=BuildOptionList(AttribA, "1", "One", "2", "Two", "3", "Three")=%%

The system returns:

<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.

How To Use the Content AMPscript Functions 53


AMPscript Guide
Arguments
• S1 String to be split
• S2 Optional parameter to indicate split. For example, comma (,) or pipe symbol (|).
Example

BuildRowsetFromString("123|456|789", "|")

Returns a data table with three rows:

123
456
789

The sample code below demonstrates how to pass attribute names and process them:

%%[

Var @queryparams
Var @row
Var @name
Var @value

Set @queryparams = BuildRowsetFromString(QueryParameter("names"),"|")

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
]%%

When passed the input below:

names=career|firstname|lastname&career=marketer&firstname=Angela&lastname=Ruiz

The AMPscript returns the following:

Passed name: career with value: marketer

Passed name: firstname with value: Angela

How To Use the Content AMPscript Functions 54


AMPscript Guide

Passed name: lastname with value: 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:

Field(Row(BuildRowSetFromString('123|456', '|'), 1), 1)

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>

Using the following function call:

BuildRowsetFromXml(@xml, "//Flight", 1)

The system returns the following rowset:

Value Xml Origin_att Dest_att Carrier_att


100.00 100.00 IND NYC ""

How To Use the Content AMPscript Functions 55


AMPscript Guide

200.00 200.00 IND LAX UAL


500 500<PerBagSurcharge>25</PerBagSurcharge> IND SEA ""

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")=%%

The system returns the content of content area 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

How To Use the Content AMPscript Functions 56


AMPscript Guide

◦ -1 Either the content area was not found or not valid. In this case, the function returns
the DefaultContent value.
Example

%%=ContentAreaByName("my contents\Stocks\Weekly Portfolio")=%%

The system returns the content of stored content area named Weekly Portfolio in the Stocks folder.

In this example:

%%=ContentAreaByName("my contents\OptOut_Page\Form\Opt Out Form


2","",0,ContentAreaByName("my contents\OptOut_Page\Form\Opt Out Form
Default”))=%%

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.

%%=ContentAreaByName(Concat("my contents\OptOut_Page\Form\Opt Out Form


",Uppercase(IIF(Empty(QueryParameter("lang")),"en-us",QueryParameter("lang")))),"
contents\OptOut_Page\Form\Opt Out Form 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")

The function returns the file.

How To Use the Content AMPscript Functions 57


AMPscript Guide

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:

<img src="http://images.example.com/logo.gif" width="35" height="20">

If, for some reason, the CorpLogo image could not be retrieved, system returns:

<img src="http://images.example.com/default.gif" width="35" height="20">

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.

How To Use the Content AMPscript Functions 58


AMPscript Guide

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

How To Use the Content AMPscript Functions 59


AMPscript Guide
Example

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:

How To Use the Content AMPscript Functions 60


AMPscript Guide

%%=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”)=%%

WAT and WATP (S1, S2)


Returns the values of the Web Analytics Tracking (WAT) parameter with the specified name (S1). Optional
parameters (S2-Sn) will be substituted for calls to the WATP function within the tracking parameter. The
WAT call parameters must be constant or numeric values. Variable, attribute, field, and faction values do
not allow job-level resolution to the desired link query string parameters.

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

Data Extension AMPscript Functions


This document contains conceptual, procedural, and scenario information about data extension AMPscript
functions.

Why Use the Data Extension AMPscript Functions


You can use these functions to interact with data extensions contained in your ExactTarget account.

How To Use the Data Extension AMPscript Functions


Create your AMPscript using the functions below and place them in the content areas of email messages
and landing pages. For example, so you can use the InsertDE() and DeleteDE() functions at the time of a
send to update information contained within a data extension.

Data Extension AMPscript Functions 61


AMPscript Guide

Enterprise and Enterprise 2.0 Accounts


When working with a data extension in the top level of an Enterprise or Enterprise 2.0 account or with a
shared data extension in an Enterprise 2.0 account, add the prefix ENT. to the data extension.

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

How To Use the Data Extension AMPscript Functions 62


AMPscript Guide

SET @CouponRow = ClaimRow("Coupon", "IsClaimed", "JobID",


JobID, "ListID", ListID, "BatchID", _JobSubscriberBatchID,
"SubscriberID", SubscriberID)
IF EMPTY(@CouponRow) THEN ]%%
No coupons available
%%[ ELSE ]%%
Your Coupon Code is %%= FIELD(@CouponRow,"CouponCode") =%%
%%[ ENDIF ]%%
</td>
</tr>
</table>

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

_CustomObjectKey bigint No Identity

CouponCode nvarchar(30) No

IsClaimed Boolean No 0

JobID int Yes

ListID int Yes

BatchID int Yes

SubscriberID int Yes

EmailAddress nvarchar(100) Yes

ClaimedDate datetime Yes

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)

How To Use the Data Extension AMPscript Functions 63


AMPscript Guide

• 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

How To Use the Data Extension AMPscript Functions 64


AMPscript Guide

Available", "JobID", JobID, "ListID", ListID, "BatchID",


_JobSubscriberBatchID, "SubscriberID", SubscriberID) =%%</td>
</tr>
</table>

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

_CustomObjectKey bigint No Identity

CouponCode nvarchar(30) No

IsClaimed Boolean No 0

JobID int Yes

ListID int Yes

BatchID int Yes

SubscriberID int Yes

EmailAddress nvarchar(100) Yes

ClaimedDate datetime Yes

DeleteDE(S1, S2, S3)


Deletes rows in a data extension with column values specified in name value pairs. No value is returned.
This function is for use with email messages at send time only.

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

How To Use the Data Extension AMPscript Functions 65


AMPscript Guide

• S2 The name of a parameter defined in the data filter


• S3 The value to be used for a parameter defined in the data filter
Example

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.

InsertDE(S1, S2, S3)


Inserts a row in a data extension (S1) with the column values listed in name value pairs (S2, S3.). No value
is returned. This function applies to email messages at send time only.

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(S1, S2, S3, S4)


Returns specified value from a data extension.

How To Use the Data Extension AMPscript Functions 66


AMPscript Guide
Arguments
• S1 The name of the data extension from which to return the specified value
• S2 Name of column from which to return a value
• S3 Name of column to match on to identify the row that contains the lookup value
• S4 Value to match S3 against
Example

%%=Lookup("PostalCode","City","PostalCode",46016)=%%

Returns the city associated with the postal code 46016 in the PostalCode data extension:

Anderson, IN

LookupOrderedRows(S1, N1, S2, S3, S4)


Returns a specified number of rows. You can specify multiple additional field/value pairs.

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 @rows2 = LookupOrderedRows("Cars",4,"Horsepower


Desc","MPG",Field(@cardata,"MPG"))

LookupOrderedRowsCS(S1, N1, S2, S3, S4)


Returns a specified number of rows. Treats any string value in a case-sensitive manner. You can specify
multiple additional field/value pairs.

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)

How To Use the Data Extension AMPscript Functions 67


AMPscript Guide

SET @RowsCSF =
LOOKUPORDEREDROWSCS("CustomObject1",10,"Region","City","greenwood","SubscriberID"
100009)

SET @RowsCST =
LOOKUPORDEREDROWSCS("CustomObject1",10,"Region","City","Greenwood","SubscriberID"
100009)

]%%

Case Insensitive Test:

Row Count: %%=ROWCOUNT(@Rows) =%%

Case Sensitive Test:

Row Count No Match: %%=ROWCOUNT(@RowsCSF) =%%

Row Count Match: %%=ROWCOUNT(@RowsCST) =%%

LookupRows(S1, S2, S3)


Returns a rowset from a data extension (S1), where the field (S2) matches the specified value (S3).
Additional field value pairs (S4 - S5 .) can be specified.

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.

LookupRowsCS(S1, S2, S3)


Returns a rowset from a data extension (S1), where the field (S2) matches the specified value (S3).
Additional field value pairs (S4 - S5 .) can be specified. Treats string values in a case-sensitive manner.

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

How To Use the Data Extension AMPscript Functions 68


AMPscript Guide
Example

%%[ VAR @Rows, @RowsCSF, @RowsCST

SET @Rows = LOOKUPROWS("CustomObject1","City","greenwood")

SET @RowsCSF = LOOKUPROWSCS("CustomObject1","City","greenwood")

SET @RowsCST = LOOKUPROWSCS("CustomObject1","City","Greenwood")

]%%

Case Insensitive Test:

Row Count: %%=ROWCOUNT(@Rows) =%%

Case Sensitive Test:

Row Count No Match: %%=ROWCOUNT(@RowsCSF) =%%

Row Count Match: %%=ROWCOUNT(@RowsCST) =%%

UpdateData(S1, N1, S2, S3, S4, S5)


This function updates an existing row in a data extension (S1) for the specified number of columns used to
build the where clause (N1) listed in name value pairs (S3, S4 .) followed by a list of columns to be updated
in name value pairs (SN, SN+1). The number of rows affected is returned. For use with landing pages and
SMS messages only.

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())

UpdateDE(S1, N1, S2, S3, S4, S5)


This function updates an existing row in a data extension (S1) for the specified number of columns used to
build the where clause (N1) listed in name value pairs (S2, S3.) followed by a list of columns to be updated
in name value pairs (SN, SN+1). No value is returned. For use with email messages at send time only.

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

How To Use the Data Extension AMPscript Functions 69


AMPscript Guide

• 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())

UpsertData(S1, N1, S2, S3, S4, S5)


This function updates an existing row in a data extension (S1) for the specified number of filter columns
(N1) listed in name value pairs (S2, S3 .) followed by a list of columns to be updated in name value pairs
(SN, SN+1). If no data exists in that row, the specified data is added to the row. The number of rows affected
is returned. For use with landing pages and SMS messages only.

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())

UpsertDE(S1, N1, S2, S3, S4, S5)


This function updates an existing row or inserts a new row if a matching row is not for update in a data
extension (S1) for the specified number of filter columns (N1) listed in name value pairs (S2, S3) followed
by a list of columns to be updated in name value pairs (SN, SN+1). No value is returned. For use with email
messages at send time only.

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())

Was This Page Helpful

• Yes No
Suggestion:

Please enter your email or phone, so we can contact you:

How To Use the Data Extension AMPscript Functions 70


AMPscript Guide

Enter the digits 17625 backwards:


Submit Feedback

DateTime AMPscript Functions


This document contains conceptual, procedural, and scenario information about DateTime AMPscript
functions.

Why Use the DateTime AMPscript Functions


You can use these functions to include and manipulate date and time data within an email message or
landing page.

How To Use the DateTime AMPscript Functions


Create your AMPscript using the functions below and place them in the content areas of landing pages and
email messages. For example, you can use the Now() function to place the time of a send in an email
message.

DateAdd(D1, I1, S1)


Returns the sum of a date and an integer, along with a time stamp.

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")=%%

The system returns tomorrow’s date, along with a time stamp.

DateDiff(D1, D2, S1)


Returns the difference between two dates.

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

DateTime AMPscript Functions 71


AMPscript Guide

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")

System returns a local time of 2: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)=%%

How To Use the DateTime AMPscript Functions 72


AMPscript Guide

Converted Back to System Time


%%=LocalDateToSystemDate(@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.

HTTP AMPscript Functions


This document contains conceptual, procedural, and scenario information about HTTP AMPscript
functions.

Why Use the HTTP AMPscript Functions


You can use these functions to include and manipulate web content within email messages and landing
pages.

HTTP AMPscript Functions 73


AMPscript Guide

How To Use the HTTP AMPscript Functions


Create your AMPscript using the functions below and place them in the content areas of landing pages and
email messages. For example, you can use the URLEncode() function to encode spaces or non-
alphanumeric characters contained in a URL for use by your subscribers.

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")

System returns the content of 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

How To Use the HTTP AMPscript Functions 74


AMPscript Guide
Example

%%=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:

Customer_ID Type Link


123 Flight http://example.com/flights/
123 Car http://example.com/cars/
456 Hotel http://example.com/hotels/

%%[
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:

How To Use the HTTP AMPscript Functions 75


AMPscript Guide

%%[Set @email = 'aruiz@example.com'


Set @firstName = 'Angel'
Set @url =
Concat('https://www.example.com?email=',@email),'&name=',@firstName]%%

<a href = "%%=RedirectTo(@url)=%%">Click Here</a>

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.

How To Use the HTTP AMPscript Functions 76


AMPscript Guide

Microsite and Landing Page AMPscript Functions


This document contains conceptual, procedural, and scenario information about microsite and landing
pages AMPscript functions.

Why Use the Microsite and Landing Page AMPscript Functions


You can use these functions to interact with microsites and landing pages within your ExactTarget
account.

How To Use the Microsite and Landing Page AMPscript Functions


Create your AMPscript using the functions below and place them in the content areas of microsites and
landing pages. For example, you can use the InsertData() and DeleteData() functions in a landing page to
manipulate data in a data extension. If you notice problems with the URL involved with these functions,
your account may need further configuration. Contact your ExactTarget representative for more
information.

AuthenticatedEmployeeID()
Returns the employee ID of the authenticated landing page user.

Example

set @ID = AuthenticatedEmployeeID()

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

set @address= AuthenticatedEmployeeNotificationAddress()

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

set @username = AuthenticatedEmployeeUserName()

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.

Microsite and Landing Page AMPscript Functions 77


AMPscript Guide
Example

set @ID = AuthenticatedEnterpriseID()

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

set @ID = AuthenticatedMemberID()

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

set @membername = AuthenticatedMemberName()

The system sets @membername to the value of the member name for the authenticated landing page user.

DeleteData(S1, S2, S3)


Deletes rows in a data extension with column values specified in name value pairs. The number of rows
affected is returned. You can also use this function with SMS data.

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.

InsertData(S1, S2, S3)


Inserts a row in a data extension (S1) with the column values listed in name value pairs (S2, S3…). The
number of rows affected is returned. You can also use this function with SMS data.

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

How To Use the Microsite and Landing Page AMPscript Functions 78


AMPscript Guide
Example

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

IsNullDefault(RequestParameter("ExampleParameter"), "Null default value")

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:

A URL specific to the landing page on which the coupon is hosted.

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:

How To Use the Microsite and Landing Page AMPscript Functions 79


AMPscript Guide

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.

Social AMPscript Functions


This document contains conceptual, procedural, and scenario information about social AMPscript
functions.

Why Use the Social AMPscript Functions


You can use these functions to interact with social networking services via email messages or landing
pages contained in your ExactTarget account.

How To Use the Social AMPscript Functions


Create your AMPscript using the functions below and place them in the content areas of email messages
and landing pages.

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

Social AMPscript Functions 80


AMPscript Guide
Example
For the function shown below:

GetPublishedSocialContent("SocialRegion1")

System returns the content contained in 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.

<!-- RegionStart[ name:"Shared content region 1",


title:"First shared email content",
description:"This is an example of shared content",
csskey:"portfolio css 1"] -->

<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!&nbsp;
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/

How To Use the Social AMPscript Functions 81


AMPscript Guide

social_default_facebook_icon.jpg" alt="Facebook" title="Facebook"


border="0"></a>
</td>
</tr>
</table>
<!-- RegionEnd[ name:"Shared content region 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

<!-- RegionStart[ name:"Shared content region 1",


title:"First shared email content",
description:"This is an example of shared content",
csskey:"portfolio css 1"] -->

<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!&nbsp;
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>

How To Use the Social AMPscript Functions 82


AMPscript Guide

</table>
<!-- RegionEnd[ name:"Shared content region 1"] -->

Utilities AMPscript Functions


This document contains conceptual, procedural, and scenario information about utilities AMPscript
functions.

Why Use the Utilities AMPscript Functions


You can use these functions to perform basic functions for an email message or landing page within
your ExactTarget account. For example, you can use the Concat() function to bring together the values of
several variables into a single text string within an email message.

How To Use the Utilities AMPscript Functions


Create your AMPscript using the functions below and place them in the content areas of email messages or
landing pages.

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)=%%

The system returns:

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.

VAR @AttributeName, @AttributeValue


SET @AttributeName =

Utilities AMPscript Functions 83


AMPscript Guide

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)

How To Use the Utilities AMPscript Functions 84


AMPscript Guide
Example

%%[
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)

The system returns:

Given the function below:

Char(65,3)

The system returns:

AAA

Given the function below:

%%=CHAR(65)=%%%%=CHAR(66)=%%%%=CHAR(67)=%%

The system returns:

ABC

How To Use the Utilities AMPscript Functions 85


AMPscript Guide

The code sample below pulls content from a data extension and replaces and carriage return-line feed
combinations with an HTML <br> tag.

%%[

VAR @content, @replacedContent

/* This will pull the content out of the DE and replace any CR-LF's with
HTML BR tags. */

SET @content = Lookup("ReplaceTest", "Value", "Key", "1")

SET @replacedContent = Replace(@content, Concat(CHAR(13), CHAR(10)),


"<BR>")

]%%
%%=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")=%%

The system returns:

abc

DecryptSymmetric(S1, S2, S3, S4, S5, S6, S7, S8)


Decrypts encrypted 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.

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.

How To Use the Utilities AMPscript Functions 86


AMPscript Guide
Arguments
• S1 Encrypted 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 @clearData variable to the value of the @endData once the function decrypts
that data. This 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.

SET @clearData=DecryptSymmetric(@encData, "AES", @null, "aardvark",


@null, "0000000000000000", @null, "00000000000000000000000000000000")

The example below uses external keys instead of provided values:

SET @clearData=DecryptSymmetric(@encData, "AES", @passwordExternalKey,


@null, @saltExternalKey, @null, @IVExternalKey, @null)

SET @clearData=DecryptSymmetric(@encData, "AES", "passwordExternalKey",


@null, "saltExternalKey", @null, "IVExternalKey", @null)

Divide(N1, N2)
Returns the result (quotient) of dividing the first argument by the second argument.

How To Use the Utilities AMPscript Functions 87


AMPscript Guide
Arguments
• N1 Value to be divided—the dividend.
• N2 Value to divide by—the divisor.
Example
Given @abc=100 and @def=5

%%=Divide(@abc,@def)=%%

The system returns:

20

Domain(S1)
Returns the domain portion of an email address.

Arguments
• S1 Email address
Example

%%=Domain(sales@example.com)=%%

The system returns:

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)

How To Use the Utilities AMPscript Functions 88


AMPscript Guide

▪ 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.

SET @encData=EncryptSymmetric("Example", "AES", @null, "password", @null,


"0000000000000000", @null, "00000000000000000000000000000000")

The examples below use external keys instead of provided values.

SET @encData=EncryptSymmetric("Example", "AES", @PasswordExternalKey,


@null, @saltExternalKey, @null, @IVExternalKey, @null)

SET @encData=EncryptSymmetric("Example", "AES", "PasswordExternalKey",


@null, "saltExternalKey", @null, "IVExternalKey", @null)

This example uses the ebc mode of the DES algorithm:

SET @encData=EncryptSymmetric("Example", "des;mode=ecb;padding=zeros",


@null, “0x7FEBCBCBCB9BCB01”, @null, @null, @null, @null)

Empty (V1)
Returns True if the value is the empty string or NULL.

Arguments
• V1 Variable to evaluate

How To Use the Utilities AMPscript Functions 89


AMPscript Guide
Example
Given @abc=27

%%=Empty(@abc)=%%

The system returns:

False

Format (V1, S1)


Formats the value according to the string you specify.

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")=%%

System returns today’s date in MM/dd/yyyy format.

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().

How To Use the Utilities AMPscript Functions 90


AMPscript Guide

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

For the code below, the system returns 1:

%%[
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

How To Use the Utilities AMPscript Functions 91


AMPscript Guide
Example
If the email address joe@example.com is valid, then the function listed below will return a "true" value.
Otherwise, the function below returns a "false" value.

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!

How To Use the Utilities AMPscript Functions 92


AMPscript Guide

%%=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.")

Returns the MD5 hash tag 13562b471182311b6eea8d241103e8f0.

MD5("This is a string.", "UTF-16")

Returns the MD5 hash tag 992b4a733b5f27475f52021f09120cc5.

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

How To Use the Utilities AMPscript Functions 93


AMPscript Guide

Given @abc=10 and @def=4

%%=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

%%[ var @output


Set @output = "My output"
Output(Concat(@output," is a success!")) ]%%

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.

How To Use the Utilities AMPscript Functions 94


AMPscript Guide
Arguments
• V1 The code that produces the results to be output by the system
Example

%%[ var @output


Set @output = "My output"
OutputLine(Concat(@output," is a success!")) ]%%

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.

How To Use the Utilities AMPscript Functions 95


AMPscript Guide
Arguments
• S1 The string to be searched
• S2 The regular expression to use in the search
• S3 The name or ordinal of the matching group to return
• S4 Repeating string parameter of regular expression options to use
You can use any value from the .NET RegexOptions enumeration, such as IgnoreCase and Multiline.

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

SET @sourceStr = "ABC_123_DEF_456";

/* RegEx without group names */


SET @regEx1 = ".*_([0-9]+)_.*_([0-9]+)"

/* RegEx with group names */


SET @regEx2 = ".*_(?<FirstNumber>[0-9]+)_.*_(?<SecondNumber>[0-9]+)"
]%%

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(V1, S1, S2)


Replaces the first string value with the second string value in the variable.

How To Use the Utilities AMPscript Functions 96


AMPscript Guide
Arguments
• V1 The variable on whose value the replace operates
• S1 The string to replace
• S2 The string to use to replace S1
Example
Given @name=The 2007 model is better.

%%=Replace(@name,"2007","2008")=%%

System returns:

The 2008 model is better.

ReplaceList(S1, S2, S3,...Sn)


Searches a string value for one or more string values you specify and replaces those values with another
string value.

Arguments
• S1 String value to search
• S2 Replacement string
• S3…Sn String values to be replaced with the value in S2
Example

ReplaceList("ABCDEFG", "X", "A", "C", "E", "G")

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

%%=SHA256("Insert Text Here","UTF-16")=%%

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.

How To Use the Utilities AMPscript Functions 97


AMPscript Guide
Arguments
• S1 The alphanumeric string on which the SHA512 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

%%=SHA512("Insert Text Here","UTF-16")=%%

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

StringToDate("2009-10-31 08:00 AM")

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.")

Returns the hex string 54686973206973206120737472696e672e.

Substring(S1, I1, I2)


Returns the portion of the specified string starting with the specified character position and no longer
than the specified length. If the specified character position is greater than the length of the specified
string, an empty string is returned.

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

How To Use the Utilities AMPscript Functions 98


AMPscript Guide
Example

%%=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

%%=Trim(" Text ")=%%

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)=%%

How To Use the Utilities AMPscript Functions 99


AMPscript Guide

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

Getting Started With AMPscript


This guide contains conceptual, scenario, and procedural information for integrating AMPscript into your
email sends and landing pages. It includes sample code and links to procedures to help you understand the
power of AMPscript and accomplish your own AMPscript projects.

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:

• A unique customer ID number


• First Name
• Last Name
• Preferred Name
• Street Address
• City
• State

Getting Started With AMPscript 100


AMPscript Guide

• 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:

• Creating variables in AMPscript


• Using variables to set values in a data extension
• Print the values of variables to the screen
The AMPscript
The entire AMPscript for this email is printed below:

AMPscript 101-401 101


AMPscript Guide

%%[
/* 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 */
]%%

The AMPscript 102


AMPscript Guide

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.

%%= 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) =%%

The email itself begins with the following template:

The AMPscript 103


AMPscript Guide

From here, you cut-and-paste the AMPscript into a content area, as shown below:

The AMPscript 104


AMPscript Guide

Note the text version of the same email as well:

The AMPscript 105


AMPscript Guide

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:

The AMPscript 106


AMPscript Guide

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:

• Using an if/else statement to insert a customer's preferred name


• Inserting dynamic content into an email based on a customer's status
• Inserting an estimated shipping date based on the customer's ZIP code
The full AMPscript code for this email is shown below:

%%[/* 201 */
Var @memid, @fname, @lname, @prefname, @address, @city, @state, @zip,

AMPscript 201 107


AMPscript Guide

@mempref, @plat, @ship

Set @memid = MemberID


Set @fname = FirstName
Set @lname = LastName
Set @prefname = PrefName
Set @address = Address
Set @zip = Zip
Set @city = Lookup("ShipTimes","city","zip",@zip)
Set @state = Lookup("ShipTimes","state","zip",@zip)
Set @mempref = MemPref
Set @plat = Plat

/* 201 */ ]%%%%[ if not empty(@prefname) then ]%%%%= v(@prefname) =%%%%[


else ]%%%%= v(@fname) =%%%%[ endif
]%%, below are your account detailsName

First Name:%%= v(@fname) =%%Last Name:%%= v(@lname) =%%

%%[ if not Empty(@prefname) then ]%%Preferred Name:%%= v(@prefname) =%%

%%[ endif ]%%Address

Address:%%= v(@address) =%%City:%%= v(@city) =%%


State:%%= v(@state) =%%Zip:%%= v(@zip) =%%

Member Preferences

Shopping Preference:%%= v(@mempref) =%%Platinum Member:%%[ if @plat ==


"N" then ]%%

%%= RedirectTo(Concat('http://example.com?s=',_subscriberkey)) =%%

Sign-Up %%[ else ]%%%%= v(@plat) =%%%%[ endif ]%%

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


In the section of AMPscript shown below, the values of two variables (@city and @state) are set by
retrieving information from the ShipTimes data extension:

Set @city = Lookup("ShipTimes","city","zip",@zip)


Set @state = Lookup("ShipTimes","state","zip",@zip)

AMPscript 201 108


AMPscript Guide

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.

%%[ if not empty(@prefname) then ]%%%%= v(@prefname) =%%%%[ else ]%%%%=


v(@fname) =%%%%[ endif]%%

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.

<strong>%%[ ifnot empty(@prefname) then ]%%%%= v(@prefname) =%%%%[ else


]%%%%= v(@fname) =%%%%[ endif ]%% </strong>, below are your account
details

AMPscript 201 109


AMPscript Guide

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.

AMPscript 201 110


AMPscript Guide

Platinum Status If/Else Statement


In the section of AMPscript shown below, the application determines whether the subscriber is a Platinum
member. If the subscriber hasn't joined the Platinum program yet, the email contains a link prompting the
subscriber to sign up on a separate web page. If the subscriber is a Platinum number, the email confirms
that status by displaying a capital Y.

Platinum Member: <strong style="color: #000;">%%[ if @plat == "N" then


]%%<a href="%%=
RedirectTo(Concat('http://example.com?s=',_subscriberkey)) =%%"
alias="Platinum Sign-Up">Sign-Up</a>%%[ else ]%%%%= v(@plat) =%%%%[ endif
]%%</strong>

The AMPscript [ if @plat == "N" then ]%% %%=


RedirectTo(Concat('http://example.com?s=',_subscriberkey)) then displays the link if and only if the
variable is set to "N." Any other answer displays the value of the variable v(@plat) in the email.

AMPscript 201 111


AMPscript Guide

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:

• Looking up content based on a unique row


• Use the row's information to populate multiple fields in the email
• Set up error checking in case AMPscript encounters unexpected data
The full AMPscript code for this email is shown below:

%%[/* 301 */

Var @memid, @fname, @lname, @prefname, @address, @city, @state, @zip,


@mempref, @plat, @rows, @row, @ship

Set @memid = MemberID


Set @fname = FirstName
Set @lname = LastName
Set @prefname = PrefName
Set @address = Address
Set @zip = Zip
Set @mempref = MemPref
Set @plat = Plat

/* 301 */ ]%%

<div style="border-bottom: 1px solid #EEE; padding: 15px 0;"><strong>%%[


if not empty(@prefname) then ]%%%%= v(@prefname) =%%%%[ else ]%%%%=
v(@fname) =%%%%[ endif ]%%</strong>, below are your account details</div>
<div style="border-bottom: 1px solid #EEE; padding: 15px 0;">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td height="15" valign="bottom"><font size="2"
color="#444444"><strong>Name</strong></font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="30"><font size="2">First Name: <strong style="color:
#000;">%%= v(@fname) =%%</strong></font></td>
<td height="30"><font size="2">Last Name: <strong style="color:
#000;">%%= v(@lname) =%%</strong></font></td>
</tr>

AMPscript 301 112


AMPscript Guide

%%[ if not Empty(@prefname) then ]%%


<tr>
<td height="30"><font size="2">Preferred Name: <strong
style="color: #000;">%%= v(@prefname) =%%</strong></font></td>
<td></td>
</tr>
%%[ endif ]%%
<tr>
<td height="30" valign="bottom"><font size="2"
color="#444444"><strong>Address</strong></font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="30"><font size="2">Address: <strong style="color:
#000;">%%= v(@address) =%%</strong></font></td>
%%[ /* We have a zip code to look up on */

if Not Empty(@zip) then

/* Lets find our zip code in the ShipTimes Data Extension */


Set @rows = LookupRows("ShipTimes","zip",@zip)

/* We found one row of data */


if RowCount(@rows) == 1 then

/* Set the row - This now exposes all columns to our variable */
Set @row = Row(@rows,1)

/* Set the City */


Set @city = Field(@row,"city")

/* Set the State */


Set @state = Field(@row,"state")

/* Set the @ship variable to the ShipTime column */


Set @ship = Field(@row,"ShipTime")

endif

endif ]%%

<td height="30"><font size="2">City: <strong style="color:


#000;">%%= v(@city) =%%</strong></font></td>
</tr>

AMPscript 301 113


AMPscript Guide

<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 */

if not empty(@ship) then ]%%

Shipping Time: <strong style="color: #000;">%%= v(@ship) =%% %%[ if @ship


> 1 then ]%%days%%[ else ]%%day%%[ endif ]%%</strong>

%%[ /* We either didn't have a zip code or couldn't find one, prompt for
profile update */

else ]%%

We couldn't find a shipping preference. Please <a href="%%=


RedirectTo(Concat('http://example.com?s=',_subscriberkey)) =%%"
title="Update Your Profile" alias="Update Your Profile">update your
profile</a>

%%[ endif ]%%</font></td>

<td height="30"><font size="2">&nbsp;</td>


</tr>
<tr>
<td height="30" valign="bottom"><font size="2"
color="#444444"><strong>Member Preferences</strong></font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="30"><font size="2">Shopping Preference: <strong
style="color: #000;">%%= v(@mempref) =%%</strong></font></td>
<td height="30"><font size="2">Platinum Member: <strong
style="color: #000;">%%[ if @plat == "N" then ]%%<a href="%%=
RedirectTo(Concat('http://example.com?s=',_subscriberkey)) =%%"
alias="Platinum Sign-Up">Sign-Up</a>%%[ else ]%%%%= v(@plat) =%%%%[ endif
]%%</strong></font></td>
</tr>

AMPscript 301 114


AMPscript Guide

</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.

Address:%%= v(@address) =%%


%%[ /* We have a zip code to look up on */
if Not Empty(@zip) then
/* Lets find our zip code in the ShipTimes Data Extension */
Set @rows = LookupRows("ShipTimes","zip",@zip)
/* We found one row of data */
if RowCount(@rows) == 1 then
/* Set the row - This now exposes all columns to our variable */
Set @row = Row(@rows,1)
/* Set the City */
Set @city = Field(@row,"city")
/* Set the State */
Set @state = Field(@row,"state")
/* Set the @ship variable to the ShipTime column */
Set @ship = Field(@row,"ShipTime")
endif
endif ]%%City:%%= v(@city) =%%
State:%%= v(@state) =%%Zip:%%= v(@zip) =%%
%%[ /* We found a record for the zip code */
if not empty(@ship) then ]%%
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 ]%% We couldn't find a shipping preference. Please
%%= RedirectTo(Concat('http://example.com?s=',_subscriberkey)) =%%
update your profile

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.

Set @rows = LookupRows("ShipTimes","zip",@zip)

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:

AMPscript 301 115


AMPscript Guide

if RowCount(@rows) == 1 then

Otherwise, the code prompts the user to update their information:

else ]%% We couldn't find a shipping preference. Please


%%= RedirectTo(Concat('http://example.com?s=',_subscriberkey)) =%%
update your profile

If only one row is found, the code chooses that row to take data from:

Set @row = Row(@rows,1)

Once the row is locked in, the code uses the Field() function to assign values to the @city, @state, and @zip
variables:

/* Set the City */


Set @city = Field(@row,"city")
/* Set the State */
Set @state = Field(@row,"state")
/* Set the @ship variable to the ShipTime column */
Set @ship = Field(@row,"ShipTime")

The email also prints these values to the email send:

%%City:%%= v(@city) =%%


State:%%= v(@state) =%%Zip:%%= v(@zip) =%%

If there is a ship time value available, that value appears in the email send as well:

%%[ /* We found a record for the zip code */


if not empty(@ship) then ]%%
Shipping Time:%%= v(@ship) =%%%%[ if @ship > 1 then ]%%days%%[ else
]%%day%%[ endif ]%%

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:

• Using for loops as part of an email send


• Using AMPscript to change the appearance of an email send
• Filtering message context
• Creating content from blocks of code

AMPscript 401 116


AMPscript Guide

The full AMPscript for this email is shown below:

%%[/* 401 */

Var @memid, @fname, @lname, @prefname, @address, @city, @state, @zip,


@mempref, @plat, @rows,
@row, @ship

Set @memid = MemberID


Set @fname = FirstName
Set @lname = LastName
Set @prefname = PrefName
Set @address = Address
Set @zip = Zip
Set @mempref = MemPref
Set @plat = Plat

/* 401 */ ]%%%%[ if not empty(@prefname) then ]%%%%= v(@prefname) =%%%%[


else ]%%%%= v(@fname) =%%%%[ endif ]%%, below are your account
detailsName
First Name:%%= v(@fname) =%%Last Name:%%= v(@lname) =%%

%%[ if not Empty(@prefname) then ]%%Preferred Name:%%= v(@prefname) =%%

%%[ endif ]%%Address

Address:%%= v(@address) =%%

%%[ /* We have a zip code to look up on */

if Not Empty(@zip) then

/* Lets find our zip code in the ShipTimes Data Extension */


Set @rows = LookupRows("ShipTimes","zip",@zip)

/* We found one row of data */


if RowCount(@rows) == 1 then

/* Set the row - This now exposes all columns to our variable */
Set @row = Row(@rows,1)

/* Set the City */


Set @city = Field(@row,"city")

AMPscript 401 117


AMPscript Guide

/* Set the State */


Set @state = Field(@row,"state")

/* Set the @ship variable to the ShipTime column */


Set @ship = Field(@row,"ShipTime")

endif

endif ]%%City:%%= v(@city) =%%

State:%%= v(@state) =%%Zip:%%= v(@zip) =%%

%%[ /* We found a record for the zip code */

if not empty(@ship) then ]%%

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 ]%%

We couldn't find a shipping preference. Please

%%= RedirectTo(Concat('http://example.com?s=',_subscriberkey)) =%%

update your profile

%%[ endif ]%%

Member Preferences

Shopping Preference:%%= v(@mempref) =%%Platinum Member:%%[ if @plat ==


"N" then ]%%

%%= RedirectTo(Concat('http://example.com?s=',_subscriberkey)) =%%

Sign-Up %%[ else ]%%%%= v(@plat) =%%%%[ endif ]%%

%%[ /* Declare more variables that will be used specifically for our
products */

AMPscript 401 118


AMPscript Guide

Var @prodID, @prodName, @prodDesc, @price, @indicator, @color,


@totalPurchases, @decimalChar

/* Zero out our total purchases amount */


Set @totalPurchases = 0

/* Set our CSS color indicator to odd */


Set @indicator = "odd"

/* 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

/* Set the row to the row we're currently looping through */


Set @row = Row(@rows,@i)

/* Set some variables */


Set @prodID = Field(@row,"ProductID")
Set @prodName = Field(@row,"ProductName")
Set @prodDesc = Field(@row,"Description")
Set @price = Field(@row,"Price")
Set @totalPurchases = Add(@totalPurchases,Field(@row,"Price"))

/* If the CSS indicator is set to odd use a white background color */


if @indicator == "odd" then
Set @color = "#FFFFFF"
Set @indicator = "even"

/* If the CSS indicator is set to even use a gray background color */


else
Set @color = "#EEEEEE"
Set @indicator = "odd"
endif

/* Call in our recent purchases content box */ ]%%


%%= TreatAsContent(ContentAreaByName("my

AMPscript 401 119


AMPscript Guide

contents\101-401\RecentPurchases")) =%%

%%[ next @i ]%%

%%[ /* Find out if there are two characters after the decimal point */

Set @decimalChar =
Subtract(Length(@totalPurchases),IndexOf(@totalPurchases,"."))

/* We found only one character after the decimal point */

if @decimalChar == 1 then

Set @totalPurchases = Concat(@totalPurchases,"0")

/* No decimal point was found */

elseif @decimalChar == Length(@totalPurchases) then

Set @totalPurchases = Concat(@totalPurchases,".00")

endif ]%%Total Purchases:$%%= v(@totalPurchases) =%%

%%[ endif ]%%

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:

/* Zero out our total purchases amount */


Set @totalPurchases = 0

AMPscript 401 120


AMPscript Guide

/* Set our CSS color indicator to odd */


Set @indicator = "odd"

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

/* Set the row to the row we're currently looping through */


Set @row = Row(@rows,@i)

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.

/* Set some variables */


Set @prodID = Field(@row,"ProductID")
Set @prodName = Field(@row,"ProductName")
Set @prodDesc = Field(@row,"Description")
Set @price = Field(@row,"Price")
Set @totalPurchases = Add(@totalPurchases,Field(@row,"Price"))

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.

/* If the CSS indicator is set to odd use a white background color */


if @indicator == "odd" then
Set @color = "#FFFFFF"
Set @indicator = "even"

AMPscript 401 121


AMPscript Guide

/* If the CSS indicator is set to even use a gray background color */


else
Set @color = "#EEEEEE"
Set @indicator = "odd"

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.

/* Call in our recent purchases content box */ ]%%


%%= TreatAsContent(ContentAreaByName("my
contents\101-401\RecentPurchases")) =%%
%%[ next @i ]%%

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,"."))

/* We found only one character after the decimal point */


if @decimalChar == 1 then
Set @totalPurchases = Concat(@totalPurchases,"0")

/* No decimal point was found */


elseif @decimalChar == Length(@totalPurchases) then
Set @totalPurchases = Concat(@totalPurchases,".00")
endif ]%%Total Purchases:$%%= v(@totalPurchases) =%%

Scenarios
This document contains scenario information that demonstrates the use of AMPscript and functions.

Scenario 1: Concerts in Your Area


The information below demonstrates how to use AMPscript in conjunction with data extensions to send an
email message to subscribers about concerts occurring in their area. The contents of the email depend on
the subscriber's stated genre performances. Download a file containing the sample code for this scenario
here.

Scenarios 122
AMPscript Guide

Data Extensions and Relationships


The marketer creates a data extension to contain information about upcoming concerts. Each concert has
an associated genre, range of ticket prices, date, artist, venue, and city. Later, the marketer will create
AMPscript to include this information in an email based on the subscriber's city and genre preferences.

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.

The Subscriber table contains the following data:

Email Address Customer ID First Name Last Name City

ettest201@example.com 201 Angel Ruiz Indianapolis

ettest202@example.com 202 John Doe Chicago

The Customer_Genre_Preferences data extension contains the following data:

Customer ID Genre

201 Rock

201 Alt Country

201 Indie

202 Pop

202 Folk

202 Rock

The Upcoming_Shows data extension contains the following data:

Concert Low High Show


Genre Artist Venue City
ID Price Price Date

10/27/ Band Venue


101 Rock 35 45 Indianapolis
2007 A A

10/6/ Band Venue


106 Indie 15 37.5 New York
2007 B B

11/15/ Band Venue


107 Indie 25 40 Chicago
2007 C C

Scenario 1: Concerts in Your Area 123


AMPscript Guide

Concert Low High Show


Genre Artist Venue City
ID Price Price Date

Alt- 10/27/ Band Venue


108 25 47.5 Indianapolis
Country 2007 D D

10/30/ Band Venue


109 Indie 35 50 New York
2007 E E

Alt- 10/19/ Band Venue


111 15 30 Chicago
Country 2007 F F

11/2/ Band Venue


112 Indie 35 57.5 Indianapolis
2007 G G

11/6/ Band Venue


113 Folk 25 35 Chicago
2007 H H

Alt- 11/15/ Band Venue


114 15 30 Indianapolis
Country 2007 I I

10/27/ Band Venue


115 Indie 25 35 Indianapolis
2007 J J

Alt- 10/30/ Band Venue


116 15 30 New York
Country 2007 K K

10/21/ Band Venue


117 Rock 15 37.5 Chicago
2007 L L

10/19/ Band Venue


118 Indie 15 30 Indianapolis
2007 M M

11/2/ Band Venue


119 Indie 25 40 New York
2007 N N

Alt- 11/6/ Band Venue


120 25 40 Indianapolis
Country 2007 O O

11/15/ Band Venue


121 Indie 35 57/5 Chicago
2007 P P

10/27/ Band Venue


122 Indie 15 30 Chicago
2007 Q Q

Scenario 1: Concerts in Your Area 124


AMPscript Guide

Concert Low High Show


Genre Artist Venue City
ID Price Price Date

10/30/ Band Venue


123 Rock 25 35 Indianapolis
2007 R R

10/21/ Band Venue


124 Indie 35 57.5 Chicago
2007 S S

Alt- 10/19/ Band Venue


125 25 47.5 Chicago
Country 2007 T T

Alt- 11/2/ Band Venue


126 35 57.5 Indianapolis
Country 2007 U U

11/6/ Band Venue


127 Indie 25 35 Chicago
2007 V V

11/15/ Band Venue


128 Indie 15 30 Chicago
2007 W W

10/27/ Band Venue


129 Rock 35 57.5 New York
2007 X X

10/30/ Band Venue


130 Rock 25 40 Chicago
2007 Y Y

10/21/ Band Venue


131 Indie 25 47.5 New York
2007 Z Z

10/19/ Band Venue


132 Pop 35 57.5 Chicago
2007 0 0

11/2/ Band Venue


133 Folk 25 35 New York
2007 1 1

10/21/ Band Venue


138 Indie 35 50 Chicago
2007 2 2

10/29/ Band Venue


139 Indie 15 37.5 Indianapolis
2007 3 3

Alt- 11/2/ Band Venue


140 25 40 Chicago
Country 2007 4 4

Scenario 1: Concerts in Your Area 125


AMPscript Guide

Concert Low High Show


Genre Artist Venue City
ID Price Price Date

11/6/ Band Venue


141 Pop 25 35 Indianapolis
2007 5 5

11/15/ Band Venue


142 Rock 25 40 New York
2007 6 6

10/27/ Band Venue


143 Rock 25 40 Indianapolis
2007 7 7

10/30/ Band Venue


144 Rock 15 30 Chicago
2007 8 8

Alt- 10/21/ Band Venue


145 25 40 Chicago
Country 2007 9 9

10/19/ Band Venue


146 Rock 35 50 Chicago
2007 10 10

11/6/ Band Venue


148 Rock 35 50 Indianapolis
2007 11 11

AMPscript
The following AMPscript appears in the body of the email.

<html>
<body style="font-size: 12px;color: #000099; font-family: verdana;">

%%[ /* This is an AMPscript Comment */ ]%%

<p>Hi %%First Name%%,<br><br>


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!<br><br>
</p>

<h3>Upcoming Shows in %%City%%</h3>


<br><br>

%%[
/* First we want to determine if the customer has any favorite genres
stored. If not, we want to encourage them to create online */

Scenario 1: Concerts in Your Area 126


AMPscript Guide

/* Otherwise, we will loop through every genre we find */

var @rsgenre, @rowgenre, @rsshow, @rowshow, @countergenre, @countershow,


@currentgenre

SET @rsgenre = LOOKUPROWS("Customer_Genre_Preferences", "Customer ID",


[Customer ID])
]%%

%%[
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

SET @currentgenre = FIELD(ROW(@rsgenre, @countergenre), "Genre


Preference")
SET @rsshow = LOOKUPROWS("Upcoming_Shows", "City", City, "Genre",
@currentgenre)

if ROWCOUNT(@rsshow) != 0 then ]%%


<h4>%%=CONCAT("Upcoming ", @currentgenre, " Shows")=%%</h4><br>
<table width="700px" style="border: 1 solid black; font-size:
10px;color: #000099; font-family: verdana;" cellpadding="2"
cellspacing="0">
<tr style="font-size: 10px;color: #999999; font-family:
verdana; font-weight: bold;">
<td>Date</td>
<td>Artist</td>
<td>Venue</td>

Scenario 1: Concerts in Your Area 127


AMPscript Guide

<td>Tickets</td>
<td>City</td>
</tr>
%%[
for @countershow = 1 to ROWCOUNT(@rsshow) do
SET @rowshow = ROW(@rsshow, @countershow)

/* Here we are setting alternating style for the row */

if MOD(@countershow, 2)== 0 and @countershow != 1 then


]%%

<tr style="background-color: #dcdcdc;">

%%[else]%%

<tr>

%%[endif]%%

<td>%%=FORMAT(FIELD(@rowshow, "Show Date"), "ddd, MMM


d")=%%</td>
<td>%%=FIELD(@rowshow, "Artist")=%%</td>
<td>%%=FIELD(@rowshow, "Venue")=%%</td>
<td><a href="http://music.com?ConcertID=%%=FIELD(@rowshow,
'Concert ID')=%%">%%=CONCAT("From", FORMAT(FIELD(@rowshow, "Low Price"),
"C2")," to ", FORMAT(FIELD(@rowshow, "High Price"), "C2"))=%%</a></td>
<td>%%=FIELD(@rowshow, "City")=%%</td>
<tr>

%%[
next @countershow
]%%

</table>
<br><br>
%%[
endif
]%%

%%[
next @countergenre
]%%
%%[

Scenario 1: Concerts in Your Area 128


AMPscript Guide

endif
]%%

<custom name="opencounter" type="tracking"><table cellpadding="2"


cellspacing="0" width="600" ID="Table5" Border=0><tr><td><font
face="verdana" size="1" color="#444444">This email was sent to:
%%emailaddr%% <br><br><b>Email Sent By:</b>
%%Member_Busname%%<br>%%Member_Addr%% %%Member_City%%, %%Member_State%%,
%%Member_PostalCode%%,
%%Member_Country%%<br><br></font></td></tr></table><a
href="%%profile_center_url%%" alias="Update Profile">Update Profile</a>

</body>
</html>

Output
When the marketer sends the email, the application processes the code:

For Angel Ruiz:

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!

Upcoming Shows in Indianapolis


Upcoming Rock Shows
Date Artist Venue Tickets City

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

Upcoming Alt-Country Shows


Date Artist Venue Tickets City

From $25 to
Sat, Oct 27 Band D Venue D Indianapolis
$47.50

Scenario 1: Concerts in Your Area 129


AMPscript Guide

Date Artist Venue Tickets City

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

Upcoming Indie Shows


Date Artist Venue Tickets City

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

For John Doe:

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!

Upcoming Shows in Chicago

Upcoming Pop Shows

Date Artist Venue Tickets City

From $35.00
Fri, Oct 19 Band 0 Venue 0 Chicago
to $57.50

Upcoming Folk Shows


Date Artist Venue Tickets City

From $25.00
Tue, Nov 6 Band H Venue H Chicago
to $35.00

Scenario 1: Concerts in Your Area 130


AMPscript Guide
Upcoming Rock Shows
Date Artist Venue Tickets City

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

Scenario 2: Suggested Car Listings


In this example, a car broker wants to send a subscriber an email that includes a list of makes and models
of cars that the subscriber might like based on the subscriber's stated preference as to type of car.

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.

Data Extensions and Relationships


The car broker also creates a data extension that contains multiple makes and models of cars for each of
the short list of types that the subscribers could choose in the survey. The car broker creates a data
relationship to associate the car_preference attribute on the subscriber to the type column in the data
extension.

The subscriber table contains the following data:

email_address first_name last_name region car_preference

aruiz@example.com Angel Ruiz north sedan

Scenario 2: Suggested Car Listings 131


AMPscript Guide

email_address first_name last_name region car_preference

johndoe@example.com John Doe south convertible

janedoe@example.com Jane Doe north SUV

The cars data extension contains the following data:

type make model

Sedan Company A Sedan A

Sedan Company B Sedan B

Sedan Company C Sedan C

Convertible Company D Convertible A

Convertible Company E Convertible B

SUV Company F SUV A

SUV Company D SUV B

SUV Company G SUV C

SUV Company H SUV D

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 */

var @rs, @row, @cntr

/* Looking up related cars by subscriber */


/* Using lookup rows function to return a rowset of related cars to use */

SET @rs = LookupRows("Cars", "Type", car_preference)

Scenario 2: Suggested Car Listings 132


AMPscript Guide

/* Looping through each record in the recordset */

for @cntr = 1 to RowCount(@rs) do

/* If there is a value in the row, output to HTML */


SET @row = Row(@rs, @cntr)
/*Ending script block here */ ]%%

%%=Field(@row, "Make")=%% &nbsp; &nbsp; &nbsp; %%=Field(@row,


"Model")=%%

%%[ /* resuming script block here */


next @cntr
/*Ending script block */]%%
</table>

</html>

Output
When the car broker sends the email, the application processes the code:

For Angel Ruiz

Company A Sedan A

Company B Sedan B

Company C Sedan C

For John Doe

Company Convertible
D A

Company Convertible
E B

For Jane Doe

Company F SUV A

Company D SUV B

Company G SUV C

Scenario 2: Suggested Car Listings 133


AMPscript Guide

Company H SUV D

Using Personalization Strings with AMPscript


You can use system personalization strings when building AMPscript expressions. For example, you might
want to display a different message or text based on the day of the week or the month. You could the
xtdayofweek or xtmonth system personalization string, respectively, for these purposes. Other common
uses for system personalization strings include passing identifiers, such as the unique email, job, or
subscriber ID/key to a web page or web analytics solution for the purposes of tracking subscriber behavior.

Personalization strings that appear in AMPscript function calls cannot include the surrounding percent
symbols. For example, this code in AMPscript is invalid:

%%=UPPERCASE(%%emailaddr%%)=%%

This format, however, is valid:

%%=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.

Note the following:

• All personalization strings are case-insensitive.


• When working with personalization strings outside of an AMPscript block, you must include the
two sets of double percent symbols (two percent symbols on either side of
the personalization string). For example, a personalization string used in email might look like
this:
%%fullname%%

• 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

ExactTarget Personalization Strings


You can use the following personalization strings within the ExactTarget application.

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.

Using Personalization Strings with AMPscript 134


AMPscript Guide

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.

Using Personalization Strings with AMPscript 135


AMPscript Guide

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_

ExactTarget list ID and type (for example, 12345_HTML).

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.

Using Personalization Strings with AMPscript 136


AMPscript Guide

_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.

Using Personalization Strings with AMPscript 137


AMPscript Guide

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.

Contacts Personalization Strings


You can use the following personalization strings in conjunction with the Contacts application inside the
Interactive Marketing Hub.

_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.

Contacts Personalization Strings 138


AMPscript Guide

_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.

Contacts Personalization Strings 139

Anda mungkin juga menyukai