Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI Macro Not displaying correctly

Nic Omaha
Tera Guru

On our incident form I created a UI macro to show related incidents on the asset field. It is not displaying correctly like the rest of the UI macros. Below is my code, any ideas?Screenshot 2025-08-14 at 11.02.33 AM.png

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">
  <g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
  <j:set var="jvar_n" value="show_asset_incidents_${jvar_guid}:${ref}"/>

  <g:reference_decoration_custom id="${jvar_n}" field="${ref}"
    title="${gs.getMessage('Show related incidents')}"
    onclick="showAssetIncidents('${ref}')">
    
    <span class="tab_square_button tab_header_button tab_ref_contribution icon-tree-right"
          aria-label="${HTML:gs.getMessage('Show related incidents')}">
    </span>
  </g:reference_decoration_custom>

  <script>
    // Open related incidents in a clean popup (no left nav)
    function showAssetIncidents(reference) {
      var field = (reference.indexOf('.') > -1) ? reference.split('.').pop() : reference;
      var id = g_form.getValue(field);      // MUST be field-only, not table.field
      if (!id) { alert('Select an Asset first.'); return; }
      var url = 'incident_list.do?sysparm_query=' + field + '=' + id;
      var w = (window.getTopWindow ? getTopWindow() : window.top);
      w.popupOpenFocus(url, 'related_list', 950, 700, '', false, false);
    }

    // Hide the decoration when empty; show when the field has a value
    (function () {
      var field = ('${ref}'.indexOf('.') > -1) ? '${ref}'.split('.').pop() : '${ref}';
      var deco = document.getElementById('${jvar_n}');
      function toggle() { deco.style.display = g_form.getValue(field) ? 'inline-block' : 'none'; }
      toggle();
      g_form.observe(field, toggle);
    })();
  </script>
</j:jelly>
0 REPLIES 0