Need a some help on below expressions with loop | Community
Skip to main content
Level 2
March 16, 2026
Question

Need a some help on below expressions with loop

  • March 16, 2026
  • 2 replies
  • 31 views

<ctx>

<schedulePaymentData>

<schedule>...</schedule>

<schedule>...</schedule>

...

</schedulePaymentData>

</ctx>

 

 

 

 

 

<table border="1" cellpadding="4" cellspacing="0">

<tr>

<th>Payment date</th>

<th>Payment amount</th>

</tr>

<%

// rtEvent is injected automatically in Message Center templates

// rtEvent.ctx is the XML payload from your SOAP <ctx> element

// This returns all <schedule> child nodes

var schedules = rtEvent.ctx.schedulePaymentData.schedule;

// Campaign-specific E4X loop over XML collection

for each (var s in schedules) {

// Extract and normalize the values as strings

var payDate = String(s.schedulePaymentDate).trim();

var payAmount = String(s.schedulePaymentAmount).trim();

%>

<tr>

<td><%= payDate %></td>

<td><%= payAmount %></td>

</tr>

<%

}

%>

</table>

 

Please help us to write a condition to print “NO DATA” in a row when there is no schedules or schedules length/size==0.

AND

Please help us to write a condition to print only 50 rows even if there are 50+ rows in schedules.

    2 replies

    Manoj_Kumar
    Community Advisor
    Community Advisor
    March 26, 2026

    There you go

     

    <%
    var schedules = rtEvent.ctx.schedulePaymentData.schedule;
    var scheduleCount = 0;
    for (var i = 0; i < schedules.length(); i++) {
    scheduleCount++;
    }

    if (scheduleCount === 0) {
    %>
    <tr>
    <td colspan="2">No schedule data available.</td>
    </tr>
    <%
    } else {
    var maxRows = scheduleCount > 50 ? 50 : scheduleCount;
    var printed = 0;
    for each (var s in schedules) {
    if (printed >= maxRows) break;
    var payDate = String(s.schedulePaymentDate).trim();
    var payAmount = String(s.schedulePaymentAmount).trim();
    %>
    <tr>
    <td><%= payDate %></td>
    <td><%= payAmount %></td>
    </tr>
    <%
    printed++;
    }
    }
    %>

     

    Manoj  | https://themartech.pro
    AmitVishwakarma
    Community Advisor
    Community Advisor
    March 26, 2026

    HI ​@AjayBo1 

    You can handle both conditions (no rows + max 50 rows) directly in the scriptlet.

    <table border="1" cellpadding="4" cellspacing="0">
    <tr>
    <th>Payment date</th>
    <th>Payment amount</th>
    </tr>

    <%
    // Get all <schedule> nodes
    var schedules = rtEvent.ctx.schedulePaymentData.schedule;
    var maxRows = 50;

    // If no schedules → print "NO DATA"
    if (!schedules || schedules.length() == 0) {
    %>
    <tr>
    <td colspan="2">NO DATA</td>
    </tr>
    <%
    } else {
    var i = 0;
    // Loop with a hard limit of 50 rows
    for each (var s in schedules) {
    if (i >= maxRows) break;

    var payDate = String(s.schedulePaymentDate).trim();
    var payAmount = String(s.schedulePaymentAmount).trim();
    %>
    <tr>
    <td><%= payDate %></td>
    <td><%= payAmount %></td>
    </tr>
    <%
    i++;
    }
    }
    %>
    </table>

    This will always show "NO DATA" when there are no <schedule> items, and will never print more than 50 rows even if the XML contains more.

    Amit Vishwakarma - Adobe Commerce Champion 2025 | 16x Adobe certified | 4x Adobe SME