0

I have 3 data extensions:
subscribers list + lookup file with 6 columns some of them with ID numbers others empty + another lookup file with content.

I'm looping through the first lookup file using LookUp Rows to find all the IDs, then I use these IDs to identify the copy from the columns from the secondary LookUp file using LookUp (first column has the IDs).

In the HTML I only need to display the first 3 blocks of content I found (first 3 non-empty columns).

How can I do that with AMPscript?

1

If you question is how would you display the first 3 rows from the dataset you would want to setup a counter variable (@rowCount) to track which row number was matched to each record in the record set. Then, use a if statement within a "for loop" to display records 1 thru 3 using the record

<span style="display:none;">%%[
/* Using lookup rows function to return a rowset of related to use */
var @lookupValue, @numRowsToReturn, @rows, @rowCount
set @lookupValue = "A"  /* use case here - For all records, the 'Group' column has a default value of 'A' */
set @numRowsToReturn = 0  /* 0 means all */
set @rows = LookupOrderedRows("YOURDATAEXTENSION", @numRowsToReturn, "ID","Group", @lookupValue)
set @rowCount = RowCount(@rows)
]%%</span>

<table>
<tr>
<th>Num</th>
<th>ID</th>
<td>Important Field</th>
</tr>

<span style="display:none;">%%[
if @rowCount > 0 then

for @i = 1 to @rowCount do ]%%</span>
<tr>
<td>%%=v(@i)=%%</td>
<td>%%=Field(@row, "ID")=%%</td>
</tr>

<span style="display:none;">%%[
next @i
endif 
]%%</span>
</table>

However, if you are trying to display only records where certain fields are not blank, you would use the if statement and not empty function to check for those cases individually (i.e. if not Empty(@importantFieldIsPresent) then ) and use your counter variable to count up from 1 to 3 for every occurrence where you saw all your desired set of columns (first 3 non-empty columns) appear. You will need a compound if statement to handle all three columns for non-empty conditions.

i.e.

<span style="display:none;">%%[
var @myImportantFieldIsPresent

if @rowCount > 0 then

for @i = 1 to @rowCount do

   @myImportantFieldIsPresent = Field(@row, "MyImportantField")

   if not Empty(@myImportantFieldIsPresent) then

 ]%%</span>
<tr>
<td>%%=v(@i)=%%</td>
<td>%%=Field(@row, "ID")=%%</td>
<td>%%=v(@myImportantFieldIsPresent)=%%</td>
</tr>

<span style="display:none;">%%[
  endif
next @i
endif 
]%%</span>
</table>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.