AMPscript 201

From $1

    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, @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)
     
    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

    MembersDataExtension.png

    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.

    ChristaHirsch.png

    In the case of Shea Winslow, the email greeting defaults to the first name because no preferred name is available.

    SheaWinslow.png

    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.

    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.


    This page was last updated by Ryan Williams on Thu, 22 Dec 2011 16:44:48 GMT.

    If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:

     


    Was This Page Helpful?
    Suggestions or Comments:
    Name (optional):
    Email Address (optional):
    Enter 19505 backwards:
       
    Tags: (Edit tags)
    • No tags
    FileSizeDateAttached by 
    ChristaHirsch.png
    No description
    33.65 kB12:44, 22 Dec 2011AdminActions
    MembersDataExtension.png
    No description
    39.91 kB12:44, 22 Dec 2011AdminActions
    SheaWinslow.png
    No description
    33.22 kB12:44, 22 Dec 2011AdminActions
    ZipCodes-w-ShipTime.csv
    Zip Codes w City, State, Est. Ship Times
    864.67 kB12:44, 22 Dec 2011AdminActions
    Comments (0)
    You must login to post a comment.

     
    Powered by MindTouch 2010
    Admin