Help Debug Jelly Script in UI Page

Nitesh Balusu
Giga Guru

 

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">

  <!-- Server Script: This runs on the server before the page loads -->
  <g:evaluate var="jvar_attachments" jelly="true" object="true">
    var gr = new GlideRecord('sys_attachment');
    gr.addQuery('table_sys_id', '${sysparm_sys_id}');
    gr.query();
    var attachments = [];
    while (gr.next()) {
      var attachment = {};
      attachment.sys_id = gr.sys_id.toString();
      attachment.file_name = gr.file_name.toString();
      attachments.push(attachment);
    }
    gs.info("attachments are " + JSON.stringify(attachments));
    attachments; // Return the attachments array as a Java object for Jelly
  </g:evaluate>

  <!-- Jelly Code: This defines the structure of the page -->
  <div class="modal-header" id="myModal">
    <h4>Pick Category For Each Attachment</h4>
  </div>
  <div class="modal-body">
    <table id="attachmentsTable">
      <tr>
        <th>File Name</th>
        <th>Options</th>
      </tr>
      <!-- Jelly loop to iterate over the attachments -->
      <j:forEach var="attachment" items="${jvar_attachments}">
        <tr>
          <td id="attachment_${attachment.sys_id}">${attachment.file_name}</td>
          <td>
            <select class="attachment-select" id="attachment_select_${attachment.sys_id}">
              <option value="">Select an option</option>
              <option value="aaa">aaa</option>
              <option value="xxx">xxxx</option>
              <!-- Additional options can be added here -->
            </select>
          </td>
        </tr>
      </j:forEach>
    </table> <!-- Closing table tag -->
  </div>
  <div class="modal-footer">
    <button id="submitAttachments">Submit</button>
  </div>
</j:jelly>

 

 

 

The info statement in the server side script prints this:

 

 

attachments are [{"sys_id":"20b987e087e6f9102242fe29cebb3572","file_name":"Global D&A Support - SLA Report.xlsx"},{"sys_id":"35b947e087e6f9102242fe29cebb351a","file_name":"Return from leave Experience Pack.xml"},{"sys_id":"382d1fa0472ef910f611ac8e326d4308","file_name":"ServiceNow Employee Journey - Return From Leave.pdf"}]

 

 

 

However for some reason the UI page shows up like this

 

Screenshot 2023-11-13 at 3.17.34 PM.png


I don't understand why the same file name is getting printed 3 times when the JSON seems to be printing fine.

0 REPLIES 0