Content LookupRows

This function returns a rowset from a data extension where the field matches the specified value. This function returns a maximum of 2000 rows. To better control the number or order of rows returned please use the LookupOrderedRows function instead. Using the LookupOrderedRows function enhances script performance. But for this example, we will focus on how to use the standard LookupRows function.

  • LookupRows(1, 2, 3)

Content Lookup Benefits

Here are some reasons why you might want to consider using a Content Lookup approach:

  • The content lookup approach works best when emails need to support multiple languages and or segments.
  • The content lookup approach allows the dynamic email to scale to evolving business needs.
  • The content lookup approach allows your email to scale to evolving business needs.
  • The content lookup approach allows us to separate email content from the email framework which makes it easier to add, remove, or modify content without having to touch code.

Sendable Data Extension

This is the sendable data extension. You’ll notice that each subscriber has a language preference. We’ll use the language preference from the sendable DE to match against the language field from the content DE so that we can return the correct row in our LookupRows() script. You can download my sample data for the sendable DE by clicking here.


Content Data Extension

This is the content data extension. You’ll notice that each row contains content that is specific to a language. We’ll use the subscribers language preference to return the correct translated content to use within the email. Simply add more rows so that your email can scale to support additional languages. You can download my sample data for the content DE by clicking here.


LookupRows Function

This example returns copy from the content DE based on subscribers language preference.

<!-- Example Code -->
%%[
/**
* Basic Subscriber Variables
* Subscriber details from the sendable DE.
*/
SET @email_address = [email_address]
SET @language = [language]
SET @first_name = AttributeValue("first_name")
IF EMPTY(@first_name) THEN
SET @first_name = "Value Customer"
ENDIF
/**
* Email Content Variables
* Using subscribers language preference to pull email content from the content DE.
* Using ,0 to set the variable to null if the specific field is left empty in the content DE.
* Using RaiseError() to kill the send when that subscribers language pref is not represented in the content DE.
*/
SET @content = LookupRows("ENT.Demo-Matrix-Content-DE", "language", @language)
SET @contentCount = RowCount(@content)
IF @contentCount > 0 THEN
SET @contentRow = Row(@content, 1)
SET @subjectline = TreatAsContent(FIELD(@contentRow, "subjectline", 0))
SET @preheader = TreatAsContent(FIELD(@contentRow, "preheader", 0))
SET @copy1 = TreatAsContent(FIELD(@contentRow, "copy1", 0))
SET @copy2 = TreatAsContent(FIELD(@contentRow, "copy2", 0))
ELSE
RaiseError(Concat("The subscriber (", @email_address, ") uses (", @language, ") that is not represented in the content DE."), true)
ENDIF
]%%
<p>Subscriber Email Address: %%=v(@email_address)=%%</p>
<p>Subscriber Language Preference: %%=v(@language)=%%</p>
<p>Subscriber First Name: %%=v(@first_name)=%%</p>
<p>Subject Line: %%=v(@subjectline)=%%</p>
<p>Preheader: %%=v(@preheader)=%%</p>
<p>Copy1: %%=v(@copy1)=%%</p>
<p>Copy2: %%=v(@copy2)=%%</p>
<!-- Example Output (en_us) -->
Subscriber Email Address: subscriber_enus@blank.com
Subscriber Language Preference: en_us
Subscriber First Name: Nolan
Subject Line: Thank you for joining!
Preheader: We will send you AMPscript tips, tricks, and more.
Copy1: Thanks for subscribing, Nolan!
Copy2: Thank you for subscribing to our monthly newsletter. We will send you emails containing AMPscript tips, tricks, and more. We also enjoy sharing industry best practices as well. Thanks again for subscribing to our monthly newsletter.
<!-- Example Output (es_es) -->
Subscriber Email Address: subscriber_eses@blank.com
Subscriber Language Preference: es_es
Subscriber First Name: nTEST
Subject Line: ¡Gracias por unirte!
Preheader: Le enviaremos consejos, trucos y más de AMPscript.
Copy1: ¡Gracias por suscribirte, nTEST!
Copy2: Gracias por suscribirse a nuestro boletín mensual. Le enviaremos correos electrónicos con sugerencias, trucos y más de AMPscript. También disfrutamos compartir las mejores prácticas de la industria. Gracias nuevamente por suscribirse a nuestro boletín mensual.
<!-- Example Output (fr_fr) -->
Subscriber Email Address: subscriber_frfr@blank.com
Subscriber Language Preference: fr_fr
Subscriber First Name: Value Customer
Subject Line: Merci de nous rejoindre!
Preheader: Nous vous enverrons des conseils, des astuces et plus encore sur AMPscript.
Copy1: Merci pour votre subscription, Value Customer!
Copy2: Merci de vous être abonné à notre newsletter mensuelle. Nous vous enverrons des e-mails contenant des conseils, des astuces et plus encore sur AMPscript. Nous aimons également partager les meilleures pratiques de l'industrie. Merci encore de vous être abonné à notre newsletter mensuelle.
<!-- Example Output (ja_jp) -->
Subscriber Email Address: subscriber_jajp@blank.com
Subscriber Language Preference: ja_jp
Subscriber First Name: Nolo
Subject Line: ご参加ありがとうございました!
Preheader: AMPscriptのヒントやコツなどをお送りします。
Copy1: 購読していただきありがとうございます、Nolo!
Copy2: 月刊ニュースレターをご購読いただきありがとうございます。 AMPscriptのヒントやコツなどを記載したメールをお送りします。また、業界のベストプラクティスを共有することも楽しんでいます。月刊ニュースレターをご購読いただき、誠にありがとうございます。
View this gist on GitHub

Gallery