0

I am currently fetching data from a data extension using AMPscript where I have multiple records for a single user. So some users may 3 records and some may 8 records. Using the below code it shows all the records for the user but I want if the user has more than 5 records then it will show only 5.

So if the first user has 3 records it will show 3 and if the second user has 8 records it will show 5. Hope that makes sense! Can anyone help me on this. Thanks.

%%[

if @rowCount > 0 then

  for @i = 1 to @rowCount do

    var @report_owner, @report_link, @report_type
    set @row = row(@rows, @i) 
    set @report_owner = field(@row,"report_owner")
    set @report_link = field(@row,"report_link")
    set @report_type = field(@row,"report_type")
    
    set @report_owner2 = "Update done"

    ]%% <br>
    
    %%=v(@report_owner2)=%%
    
    %%[ next @i ]%%
            
    %%[ else   ]%%
    
    No rows found
    
    %%[ endif ]%%
1
  • Please update your question to include the lookup that you're using for @rows. Commented Dec 19, 2023 at 17:38

1 Answer 1

0

Updated

Change for @i = 1 to @rowCount to for @i = 1 to 5

I would suggest adding another if condition perhaps like

if @rowCount > 0 then
  If @rowcount > 5 then set @rowcount = 5
  ENDIF 
for @i = 1 to @rowCount do
4
  • Thanks for your answer. It's working for that have more than 5 records but those have records less than 5 getting an error like - "Invalid index (parameter 2) passed to Row function. Index must be less than or equal to the row count. Index Value: 3 Row Count: 2 Function: row(@rows, @i)" Commented Dec 19, 2023 at 16:15
  • updated comment to approach it differently
    – EazyE
    Commented Dec 19, 2023 at 16:32
  • It's not working but I have added another else condition for this and it works now. Thanks for your help! Appreciated it. Commented Dec 19, 2023 at 19:01
  • @MonowarHossain please mark the answer as accepted if it has been helpful Commented Dec 19, 2023 at 22:32

You must log in to answer this question.

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