0

I've run into an issue where I'm trying to pull all rows from an existing data extension using AMPscript in an email. I've been able to get a single row of the de, but I'm hitting a wall, when trying to pull multiple. I've tried assigning a default value to all rows in the DE and pulling all rows that have that value, but still haven't quite solved it.

My code below, Inbound is the field name I've set as the default of 1:

%%[
<br />
var @rows, @row, @rowCount, @Inbound, @i 
set @Inbound = AttributeValue("Inbound")  
set @inbound = "1"  
set @rows = LookupRows("JumpStart_TestDE", "Inbound", @inbound) 
set @rowCount = rowcount(@rows)  
<br />
]%%
<style type="text/css">
body {font-family:Arial, Helvetica, sans-serif; font-size: 11px; }

table.Report { width:600px; margin: 20px auto; border:1px solid #000; padding 1px; font-family:Arial, Helvetica, sans-serif; font-size: 11px; }

  table.Report td { border: 1px solid #ccc; padding: 3px 5px; }

  h1 {font-size: 18px;</style><h1 style="font-family:Arial, helvetica, sans-serif;font-size:20px;color:#808080;line-height:100%;font-weight:bold;font-style:normal;">
 Daily Report</h1><table class="Report">
 
  <tr style="font-weight:bold;">
   <td>
    FirstName</td><td>
    LastName</td><td>
    Email</td><td>
    SubmittedDate</td></tr></table> 
%%[ 
if @rowCount > 0 then 
for @i = 1 to @rowCount do 
var @FirstName, @LastName, @CreateDateTime, @SubmittedDate 
set @row = row(@rows, @i) 
set @FirstName = field(@row,"FirstName") 
set @LastName = field(@row,"LastName") 
set @Email = field(@row,"Email") 
set @SubmittedDate = field(@row,"SubmittedDate") ]%% 
%%[ next @i ]%%
<table border="1" cellpadding="0" cellspacing="0" class="Report" style="width:500px;">
 
  <tr>
   <td>
    %%=v(@FirstName)=%%</td><td>
    %%=v(@LastName)=%%</td><td>
    %%=v(@Email)=%%</td><td>
    %%=v(@SubmittedDate)=%%</td></tr></table><br>
%%[ else ]%% 
Nothing to report.<br><br>
%%[ endif ]%%

1 Answer 1

2

You put the next keyword in a wrong position. That's why it only displays information of the last record in the row set you got. I would put it after the block that you try to render the FirstName, LastName, etc..

Try to modify your block code something like this:

%%[ 
if @rowCount > 0 then 
    for @i = 1 to @rowCount do 
        var @FirstName, @LastName, @CreateDateTime, @SubmittedDate 
        set @row = row(@rows, @i) 
        set @FirstName = field(@row,"FirstName") 
        set @LastName = field(@row,"LastName") 
        set @Email = field(@row,"Email") 
        set @SubmittedDate = field(@row,"SubmittedDate") 
]%%

<table border="1" cellpadding="0" cellspacing="0" class="Report" style="width:500px;">
 
<tr>
<td>%%=v(@FirstName)=%%</td>
<td>%%=v(@LastName)=%%</td>
<td>%%=v(@Email)=%%</td>
<td>%%=v(@SubmittedDate)=%%</td>
</tr></table><br>

%%[ next @i ]%%

%%[ else ]%% 
Nothing to report.<br><br>
%%[ endif ]%%
1
  • Thank you this worked perfectly!
    – Kale
    Commented Feb 23, 2023 at 14:04

You must log in to answer this question.

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