Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

There is a JavaScript error in your browser console - error

v-paulp
Tera Contributor

Hi all ,

There is two reference type variable in catalog which is referring  to same table . and based on value selected to the first variable it's should show values to second variable. I have written below client script and script include but it is showing "There is a JavaScript error in your browser console  "this error message.

client script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    if (oldValue !== newValue) {
        g_form.clearValue('variable_two');
        var ga = new GlideAjax('getfilteroptions');
        ga.addParam('sysparm_name', 'getoptions');
        ga.addParam('sysparm_variable1', newValue);
        ga.getXMLAnswer(updatevalues);
    }

    function updatevalues(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setReferenceQual('variable_two', answer);
        g_form.addInfoMessage("Reference Qual set: " + answer);
    }
}

script inlcude

var getfilteroptions = Class.create();
getfilteroptions.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getoptions: function() {
        var variable1 = this.getParameter('sysparm_variable1');
        var arr = ['China (KH) Kangui Plant', 'Mexico (ELTJ) El Lago Plant', 'Mexico (NLTJ) Nellcor Plant', 'Dominican Republic (SIMA) San Isidro Plant', 'Boulder', 'China (CZM) Plant', 'China (KH) Kangui Plant', 'Connecticut (NH) North Haven Plant'];
        var arr1 = [];

        function removeValue(arr, valueToRemove) {
            for (var i = arr.length - 1; i >= 0; i--) {
                if (arr[i] === valueToRemove) {
                    arr.splice(i, 1);
                }
            }
            return arr;
        }

        var req = new GlideRecord('u_service_catalog_filter_variables');
        req.addQuery('sys_id', variable1);
        req.query();
        if (req.next()) {
            var value = req.getDisplayValue('u_name');
        }
        var gr = new GlideRecord('u_service_catalog_filter_variables');
        gr.addEncodedQuery('u_active=true^u_catalog_item=fbaaec411b2989506ed99603b24bcbd2^u_variable_number=2');
        gr.query();
        while (gr.next()) {
            arr1.push(gr.sys_id + '');
            var updatedArray;
            if (arr.includes(value)) {
                updatedArray = removeValue(arr1, 'd5160d7697968e142ac576d6f053af30');
            } else {
                updatedArray = arr1;
            }

        }
        return 'sys_idIN' + updatedArray.join(',');

    },

    type: 'getfilteroptions'

});

please let me know where I am making mistake

 

5 REPLIES 5

Sarthak Kashyap
Kilo Sage

Hi @v-paulp ,

 

Can you please try with below client script code

if (isLoading || newValue === '') {
        return;
    }
    if (oldValue !== newValue) {
        g_form.clearValue('variable_two');
        var ga = new GlideAjax('getfilteroptions');
        ga.addParam('sysparm_name', 'getoptions');
        ga.addParam('sysparm_variable1', newValue);
        ga.getXMLAnswer(function (answer){
                g_form.setQuery('variable_two', answer);
                g_form.setReferenceQual('variable_two', answer);
                g_form.setFilter('variable_two', answer);
                g_form.addInfoMessage("Reference Qual set: " + answer);
        });
    }

 

In Script Include define var value and var updatedArray Outside the loop.

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

 

still showing same error

image.png

Hi @v-paulp ,

 

Can you please check the logs by doing inspect from your browser.

raviteja1600
Tera Guru

Hi @v-paulp ,

 

The issue might causing due the form loading in the OnChange Client sript

 

if (isLoading || newValue === '') {
        return;
    }

 

Can you please remove these lines from your code and test it, if the issue still persists let me know.

 

If the solution works, please mark it as helpful and accept the solution,

 

Regards,

Raviteja