0

I am trying to return a row by using LookupRows but I can't seem to get past that as other functions that use my @rows variable throw an error. I am assuming it is because the LookupRows function is returning an empty array (wrongly). My Data Extension has 2 records.

%%[
var @dataExtension, @contactKey, @rows, @total, @i, @row, @cell

set @dataExtension = "HF_83_CLW_ArrivedInUSA_Tracking"
set @contactKey = "contactKey"
set @total = DataExtensionRowCount(@dataExtension)
set @rows = LookupRows(@dataExtension,@contactKey,"123456777")
]%%

%%[
FOR @i = 1 to @total DO

set @row = Row(@rows, @i)

]%%

<p>
  Rows= %%=v(@rows)=%%<br>
</p>

%%[ NEXT @i ]%%

1 Answer 1

1

Rows is not an array, you can't print it. You need to get the data extension fields you want from the row variable as below. I gave an example with firstName and emailAddress..

%%[
var @dataExtension, @contactKey, @rows, @total, @i, @row, @cell

set @dataExtension = "HF_83_CLW_ArrivedInUSA_Tracking"
set @contactKey = "contactKey"
set @total = DataExtensionRowCount(@dataExtension)
set @rows = LookupRows(@dataExtension,@contactKey,"123456777")
]%%

%%[
FOR @i = 1 to @total DO

set @row = Row(@rows, @i)
set @firstName = field(@row,"firstName")
set @emailAddress = field(@row,"emailAddress")

]%%

<p>
  firstName: %%=v(@firstName)=%%<br>
  emailAddress: %%=v(@emailAddress)=%%
  
</p>

%%[ NEXT @i ]%%
2
  • Thank you, appreciate your help. However I still get the same issue when trying to publish the page, even after adding your example. "An error occurred while previewing this content. This can happen for many reasons, including incomplete or incorrect MC scripting (AMPscript, SSJS or GTL) or missing subscriber context. Click Cancel to review your code or Publish to push the updated content live." Oct 13, 2022 at 16:39
  • Have you published the cloudpage? Oct 13, 2022 at 17:18

You must log in to answer this question.

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