Modal field not loading the values from a reference field

Shannon25
Tera Contributor

I have created a UI Page that opens a modal when a UI Action is clicked. The modal allows the user to select a name from a list of records from a reference field. I am not able to get the dropdown to load. It only says --Loading Entities--. I am checking the values from an extended table from the case table but the field that is a reference is extended from the Account 'customer_account' table. Here is the code I have. Can someone see why I am not able to get this values to load?

    <script>
        document.addEventListener("DOMContentLoaded", function () {
            var ga = new GlideAjax('GetEntityList');
            ga.addParam('sysparm_name', 'getEntities');
            ga.getXMLAnswer(function(response) {
                try {
                    var entities = JSON.parse(response);

                    // ✅ Sort alphabetically by name (case-insensitive)
                    entities.sort(function(a, b) {
                        return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
                    });

                    var select = document.getElementById('u_account');
                    select.innerHTML = '<option value="">-- Select an Entity --</option>';
                    entities.forEach(function(entity) {
                        var option = document.createElement('option');
                        option.value = entity.sys_id;
                        option.text = entity.name;
                        select.appendChild(option);
                    });
                } catch (e) {
                    alert("Failed to load entity list.");
                }
            });
        });

        function onSubmit() {
            var entityId = gel('u_account').value;

            if (!entityId) {
                alert("Please select an Entity Name.");
                return false;
            }

            var ga = new GlideAjax('AccountModalForm');
            ga.addParam('sysparm_name', 'duplicateFromEntity');
            ga.addParam('entitySysId', entityId);
            ga.getXMLAnswer(function(response) {
                try {
                    var result = JSON.parse(response);
                    if (result.error) {
                        alert("Error: " + result.error);
                    } else {
                        alert(result.message);
                        if (result.caseSysId) {
                            window.location.href = '/casetable.do?sys_id=' + result.caseSysId;
                        }
                    }
                } catch (e) {
                    alert("An error occurred while processing the response.");
                }
            });

            return false;
        }
    </script>
</j:jelly>
0 REPLIES 0