Expand my Community achievements bar.

Get ready! An upgraded Experience League Community experience is coming in January.

Need a some solution on while loop

Avatar

Level 3

Hi Team,

 

Can you please help me on writing the rtEvent expression with while loop to display in table format, for the below.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:nms:rtEvent">
<soapenv:Header/>
<soapenv:Body>
<urn:PushEvent>
<urn:sessiontoken>?</urn:sessiontoken>
<urn:domEvent>
<rtEventtype="Welcome_TTN" email="Veera@gmail.com" wishedChannel="email">
<ctx>
<employeeName>
<Name>Vinay</Name>
<Name>Veera</Name>
<Name>Vishal</Name>
<Name>Venkat</Name>
</employeeName>
</ctx>
</rtEvent>
</urn:domEvent>
</urn:PushEvent>
</soapenv:Body>
</soapenv:Envelope>

Thanks in Advance

Veera

2 Replies

Avatar

Community Advisor

Hello @veerareddyc1015,

 

something like this should work :

<table border="1" style="border-collapse: collapse; width: 100%;">
  <thead>
    <tr>
      <th style="text-align: left; padding: 8px;">Employee Name</th>
    </tr>
  </thead>
  <tbody>
    <% 
    // Iterate through each 'Name' node within the employeeName context
    for each(var employee in rtEvent.ctx.employeeName.Name) { 
    %>
      <tr>
        <td style="padding: 8px;"><%= employee %></td>
      </tr>
    <% } %>
  </tbody>
</table>

Br,

Avatar

Level 2

 

Hi veerareddyc1015,

 

The <Name> elements under <employeeName> are treated as an array in the rtEvent context. We can iterate through them using a while loop and render the values in a table format in the email HTML.

Please find the sample code below:

 

 
<table border="1" cellpadding="6" cellspacing="0">
  <tr>
    <th>S.No</th>
    <th>Employee Name</th>
  </tr>

  <%
    var i = 0;
    var empNames = rtEvent.ctx.employeeName.Name;

    while (i < empNames.length) {
  %>
      <tr>
        <td><%= i + 1 %></td>
        <td><%= empNames[i] %></td>
      </tr>
  <%
        i++;
    }
  %>
</table>

This approach correctly accesses the rtEvent context (rtEvent.ctx.employeeName.Name) and dynamically displays all employee names in a table, even if the number of <Name> nodes changes.

Hope this helps.


Thanks,
Giriprasath B