I have a Data extension and an HTML paste Email. In one of the email content block I would like to fetch some data dynamically using AMPScript from DE based on data attributes.

I have tried using lookuprows function but was not successful.

For example, there is an email address, which can possibly be present multiple times in the DE for separate products. So for each product, email should populate different fields in different emails to same subscriber.

I would like to populate below mentioned content block for each subscriber with "productURL" "productImage" "ProductName" from the DE to this content block, each identified based on the productname.

<td align="center" width="180">
<a conversion="true" href="href="%%[
SET @rowset = LookupRows("DataextensionTest","ProductNumber", testproduct, "ProductNumber", celebrate300000)
SET @row = Row(@rowset, 1)
 " target="_blank">
       <img src="SSSSS" alt="Recommended" width="180" height="180" border="0" style="border:none; margin: 0; padding:0;">


Any help with the AMPScript code to use in the content block would be highly appreciated.

Also would like to know if I have over 100 products would it be good to use if else condition to get the desired result. If so please provide the help.

error: ×The subscriber preview failed to generate. Review the details, correct all issues, and try again.
There is an error in your email. Please contact your customer service representative.
 Error 1: Script SET Statement Invalid
 An error occurred when attempting to resolve a script expression. See inner exception for detail.
 Script Expression: LookupRows("DataextensionTest","ProductNumber", bairon2990, "ProductNumber", celebrate300000)
 MemberID: 00
 JobID: 0

 The specified attribute or custom object field name was not found for this client.
 Function Call: LookupRows("DataextensionTest","ProductNumber", bairon2990, "ProductNumber", celebrate300000)
 Attribute or Field Name: bairon2990

 Invalid Content: 
 SET @rowset = LookupRows("DataextensionTest","ProductNumber", bairon2990, "ProductNumber", celebrate300000)

1 Answer 1


Currently your lookuprows() function is contradicting itself. it's built for one pair of operators to filter the data, and additional pairs are set to use the AND boolean operator. Meaning you're looking in "Dataextensiontest" for rows that have ProductNumber equal to testproduct AND ProductNumber equal to celebrate300000 which by default would return no data, since one value can't equal two things.

In order to write the lookuprows we'd need to know what columns are included in your "DataextensionTest" DE

I would also separate your Ampscript and HTML to help keep things clear, and also currently you're not defining any variables to actually use the data in the @row variable. you could try something like this:

SET @rowset = LookupRows("DataextensionTest","ProductNumber", testproduct)
SET @row = Row(@rowset, 1)
SET @url = Field(@row, "productURL")
SET @image = FIELD(@row, "productImage")
SET @name = FIELD(@row, "productName")
<td align="center" width="180">
  <a conversion="true" href="%%=v(@url)=%%" target="_blank">
    <img src="%%=v(@image)=%%" alt="Recommended" width="180" height="180" border="0" style="border:none; margin: 0; padding:0;">

This is assuming your image column in the data extension just houses a URL to the image.

  • Thanks for explaining this. But now when I have understood things a bit the whole situation is going way over my head. Here is what I am trying to achieve: I have an email with four content blocks, I wanted to populate them dynamically with Image(URL), Link(URL) and product name in each content block from a data extension. such that if a subscriber is present multiple times in a DE listed for different products he can get one email with 4 product images he has subscribed for (and is present in DE four multiple times) if not present multiple times content blocks will be blank and show nothing. Commented Feb 8, 2017 at 14:44
  • Is there any way you can change how your DE works? I think it'd be much more useful for your situation if you had a DE that had one entry per subscriber (no duplicates) and a simple Y/N for each product they can receive. That way you could have a separate DE that had information on each product in rows, so you can pull the info in one shot. I'm not sure how loops increment across content blocks yet, as my company currently uses the classic content builder still. Essentially we'd keep the code above, but add another lookup before it to look for which products the subscriber could get. Commented Feb 8, 2017 at 18:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .