0

I am using a for loop to print out some records from a data extension but it always brings back a 500 error on my CloudPage where it is hosted.

I've simplified the code and wrapped in SSJS to try and catch the error but the page still returns 500.

Here is the code:

<script runat="server">
   Platform.Load("Core", "1");
   try {
</script>

%%[

VAR @periodsDataExtension
SET @periodsDataExtension = 'PeriodsCopy'
    
/* FIND PERIOD ID */
SET @PeriodRows = LookupOrderedRows(@periodsDataExtension, 500, 'start_date desc', 'active', '1')
OutputLine(Concat('RowCount: ', ROWCOUNT(@PeriodRows)))
FOR @i TO ROWCOUNT(@PeriodRows) DO
    /* Stripped everything out incase its causing issues */
NEXT @i

]%%

<script runat="server">
    } catch(e) { Write(Stringify(e)); }
</script>

If I remove the FOR loop, the code executes fine and shows the row number from my OutputLine above.

Any ideas?

1

your FOR line has to be changed to:

FOR @i = 1 TO ROWCOUNT(@PeriodRows) DO

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.