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

Need some help to write a condition on below expressions with loop.

  • March 17, 2026
  • 9 replies
  • 270 views

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.

 

FYI,

<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>

    9 replies

    Nolan_Chabert
    Adobe Employee
    Adobe Employee
    March 17, 2026

    Hi ​@AjayBo1 

    did you try to use the if tatement wit hthe size of your var s? and apply a else with <td> no data.

    Thanks 

    Nolan 

    AjayBo1Author
    Level 2
    March 17, 2026

    Hi ​@Nolan_Chabert ,

    Yes, we have tried. its not working for “No data”.

    Nolan_Chabert
    Adobe Employee
    Adobe Employee
    March 17, 2026

    Hi ​@AjayBo1 

    Can you please share your code with the IF ELSE lengh? Thanks 

    Nolan 

    Nolan_Chabert
    Adobe Employee
    Adobe Employee
    July 6, 2026

    Hi ​@AjayBo1 , are you still facing the issue?

    Level 2
    July 23, 2026
     
    var schedules = rtEvent.ctx.schedulePaymentData.schedule;

    if (!schedules || schedules.length() == 0) {
    %>
    <tr>
    <td colspan="2">NO DATA</td>
    </tr>
    <%
    } else {

    var count = 0;

    for each (var s in schedules) {
    if (count >= 50) break;

    var payDate = String(s.schedulePaymentDate).trim();
    var payAmount = String(s.schedulePaymentAmount).trim();
    %>

    <tr>
    <td><%= payDate %></td>
    <td><%= payAmount %></td>
    </tr>

    <%
    count++;
    }
    }
    %>

    This handles both scenarios: showing NO DATA when the schedule list is empty and limiting the output to the first 50 rows.

    ccg1706
    Community Advisor
    Community Advisor
    July 28, 2026

    Hi ​@AjayBo1

     

    You can use schedules.length () to display “NO DATA” when the XML list is empty and Math.min(schdeules.length(),50) to limit the output to the first 50 schedules. 

     

    Additional documentation useful to check:Transactional messaging

     

    If helpful I can send you the code. 

     

    Kind regards, 

    Celia Castilla