Search code examples
servicenow

getDispalyValue('field_name') is not working when in a UI Macro


I have a UI macro that fetches a list of records and displays them into a table above some form fields. I'm not using an embedded list because I want the table to read-only and so far, haven't found a way to make an embedded list read.

In my macro I have :

<g2:evaluate var="jvar_records" object="true" >
        var gr = new GlideRecord(Tables.PTC);
        gr.query();
        gr;
</g2:evaluate>

<j2:while test="$[jvar_records.next()]">
     <tr class="$[jvar_class]">
            <td>$[jvar_records.getValue('arrival_date')]</td>
            <td>$[jvar_records.getValue('departure_date')]</td>
            <td>$[jvar_records.getDisplayValue('certifier')]</td>
            <td>$[jvar_records.getDispalayValue('trip.depart_reason_code')]</td>
    </tr>
</j2:while>

The field certifier and trip are Reference fields, that I want to get the dispaly value of. But they keep coming back as empty in the macro. It works in a background-script just fine. If I just get the value jvar_records.getValue('certifier') it correctly gives me the sys_id.

What am I missing?


Solution

  • Am relatively certain that, outside of the <g2: evaluate> tag, Jelly is constrained to client side API. Client side GlideRecord doesn't have a getDisplayValue function.

    What I would do is have your g2:evaluate actually loop through the records and build an array of normal JavaScript objects with just the values you will need, then return that array of objects as opposed to returning the GlideRecord object with query results.