Checking lookupRow() results

Even though your email will pass validation in Salesforce Marketing Cloud, if you don’t check for positive lookupRows() results with rowcount() before using the row() function, then you may end up with a run-time error that aborts your send.

These kinds of errors are a pain to track down in the SFMC platform. Save yourself some debugging/support call time.

Don’t do this:

Do this:

AMPScript Lookup Examples

In Marketing Cloud, there are several ways to retrieve external data with AMPscript inside your email, landing page or SMS message. Here are few ways to go about it.

Suppose you have a Data Extension that contains these rows (and is not your sending audience):

LookupColumnDEColumn1DEColumn2
wheeNeoKeanu Reeves
wheeTrinityCarrie-Anne Moss
wheeMorpheusLaurence Fishburne
whoaAgent SmithHugo Weaving

Lookup value of single column value from a certain row

Output

DEColumn1 is Agent Smith

Lookup multiple column values from a single row

Output

DEColumn1 is Neo, DEColumn2 is Keanu Reeves

Lookup multiple column values from multiple ordered rows

Output


Row 1, DEColumn1 is Trinity, DEColumn2 is Carrie-Anne Moss
Row 2, DEColumn1 is Neo, DEColumn2 is Keanu Reeves
Row 3, DEColumn1 is Morpheus, DEColumn2 is Laurence Fishburne

For further reference:

Updates

  • 2017-10-19 – Added example Data Extension and output
  • 2018-08-24 – update reference links