AMPscript 301

This scenario includes information on these aspects of using AMPscript:

  • Looking up content based on a unique row
  • Use row information to populate multiple fields in the email
  • Set up error checking in case AMPscript encounters unexpected data

This AMPscript provides the content for the entire email message:

The majority of this AMPscript code appears 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. This AMPscript also assists the sender by prompting the subscriber to visit their online profile to update any incorrect or missing ZIP code information.

The code just below the Address field takes the @zip variable and follows the code to insert the correct information. That code 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.

Only one row should contain that ZIP code value, so this code only goes into effect if the RowCount()function finds a value of 1:

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

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

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

The email also prints these values to the email send:

Any available ship time value appears in the email send as well:

One final if/else statement determines whether the message includes the word day or days as appropriate to the number value in the @ship variable.