1

I am building an email that will contain a checklist of items that need to be populated from a related object. Each checklist item is contained in a separate row, and the number of rows could vary by email sent. So far, I haven't been able to produce any rows from this code:

%%[
var @rows, @row, @rowCount, @lookupValue, @i

set @lookupValue = "_ContactKey"
set @rows = LookupOrderedRows("Checklist",0,"Date_Added desc","Contact", @lookupValue)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then

for @i = 1 to @rowCount do

var @DEColumn1
set @row = row(@rows,@i) /* get row based on counter */
set @DEColumn1 = field(@row,"Type")

]%%

Here are the items you are still missing:

%%=v(@i)=%%:  %%=v(@DEColumn1)=%%

%%[

next @i ]%%

%%[ else ]%%

No rows found

%%[ endif ]%%   

Here are my thoughts/questions (on top of the debug):

  1. To use LookupOrderedRows, your DE must be indexed or the rows numbered in some way, correct?
  2. I attempted this same operation with just LookupRows, and still no luck. The data we are pulling is not necessarily ordered, it's just a collection of rows associated to an application that rolls up to the contact ID.

Any help would be appreciated!

PS- you all probably know where I got this code :)

2
  • Also, I updated the lookup examples on my blog for clarity. Oct 6, 2017 at 11:18
  • Awesome, this helped fix it. Thanks for the quick response! Oct 6, 2017 at 15:32

1 Answer 1

2

You're just not retrieving the lookup value from the send context -- it's evaluating _ContactKey as a literal string.

Easy fix -- drop the double quotes or better yet, use the AttributeValue() function:

%%[
var @rows, @row, @rowCount, @lookupValue, @i

set @lookupValue = _ContactKey
/* or better */
set @lookupValue = AttributeValue("_ContactKey") 

set @rows = LookupOrderedRows("Checklist",0,"Date_Added desc","Contact", @lookupValue)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then

for @i = 1 to @rowCount do

var @DEColumn1
set @row = row(@rows,@i) /* get row based on counter */
set @DEColumn1 = field(@row,"Type")

]%%

Here are the items you are still missing:

%%=v(@i)=%%:  %%=v(@DEColumn1)=%%

%%[

next @i ]%%

%%[ else ]%%

No rows found

%%[ endif ]%% 

You must log in to answer this question.

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