Client catalog script stopped working

nimishpatel
Tera Contributor
Here's a catalog client script that I'm having issues with  that's located in a catalog item that suddenly stopped working. I can't figure out what changed. both dev and prod instances are on Vancouver. Please let me know if anyone has any ideas or if you need more specifics.
 
The catalog item has a few variables out of those few two of them are supposed to interact which I think that's where the client catalog script comes in. it's supposed to populate variable 2 based off of what is selected in variable 1. but it just ends up stating answer is null but it's working on my dev instance.
 
Variable 1 is of type Multiple choice: none, windows, mac and monitor.
Variable 2 is of type List collector.
 
In the dev instance it gives me the following XML response:
 

XML Response: <ml answer="Apple MacBook Pro, Apple Magic Keyboard with Numeric Keypad, Mouse, Headset | |1509aa4387b79d10d1d5cb7eebb35b5, 71d96a4387b79d10d1d5cb7edebb35be, 9ee9668387b79d10d1d5cb7e@ebb352a, c9f9668387b79d10d1d5cb7edebb35 e5" sysparm max="15" sysparm name="options" sysparm processor="findOptions"></xml>

 

Answer: Apple MacBook Pro,Apple Magic Keyboard with Numeric Keypad, Mouse, Headset ||1509a4387b79d10d1d5cb7edebb35b5,71d96a4387b79d10d1d5cb7edebb35be,9ee9668387b79d10d1d5cb7e0ebb352a, c9f9668387b79d10d1d5cb7e0ebb355

 

In the prod instance it gives me the following XML response:

 

XML Response: <xml sysparm_max="15" sysparm_name="options" sysparm_processor="findOptions"></xml>

Answer: null

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var bundleSelected = g_form.getValue('u_bundle');

    var ga = new GlideAjax('findOptions');
    ga.addParam('sysparm_name', 'options');
    ga.addParam('sysparm_u_bundle', bundleSelected);
    ga.getXML(doSomething);
}

function doSomething(response) {
    var xmlResponse = response.responseXML.documentElement;
    var answer = xmlResponse.getAttribute('answer');

    // Log the XML response and answer for debugging
    console.log('XML Response:', xmlResponse);
    console.log('Answer:', answer);

    // Check if answer is not null or undefined before splitting
    if (answer !== null && answer !== undefined) {
        var arr = answer.split('||');

        if (window === null) {
            g_form.setValue('hardware_options', arr[1], arr[0]);
        } else {
            addItemsToList('hardware_options', arr[1], arr[0]);
        }
    } else {
        // Handle the case where answer is null or undefined
        console.error('Answer is null or undefined.');
    }
}

function addItemsToList(listCollector, sysid, displayValue) {

    g_form.clearValue('hardware_options');
	var bundles = g_form.getValue('u_bundle');
    if (bundles == 'mac' || bundles == 'windows' || bundles == 'monitor') {
        var varName = listCollector;
        var leftBucket = document.getElementById(varName + '_select_0');
        var rightBucket = document.getElementById(varName + '_select_1');
        var selectedOptionsIDs = [];


        rightBucket.options.length = 0;
        if (sysid != '') {
            var myCIArray = sysid.split(',');
            var myDisplayValue = displayValue.split(',');
            for (i = 0; i < myCIArray.length; i++) {
                var option = document.createElement('option');
                option.value = myCIArray[i];
                option.text = myDisplayValue[i];
                rightBucket.add(option);
            }
        }
        sortSelect(rightBucket);
        moveSelectedOptions(selectedOptionsIDs, leftBucket, rightBucket, '--None--');
    } else {
        g_form.clearValue('hardware_options');
    }
}

 

 

6 REPLIES 6

AshishKM
Kilo Patron
Kilo Patron

Hi @nimishpatel , 

Did you check the script include ( findOptions ) method for this options logic, one DEV its returning the values but from PROD there is not data coming. So check that code first. 

 

Share the script include code.

 

-Thanks,

AshishKMishra

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hi @AshishKM ,

 

Here's the findOptions script include. It seems to be the same from dev and prod.

var findOptions = Class.create();
findOptions.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    options: function() {

        var bundleSelected = this.getParameter('sysparm_u_bundle');
        var hardwareBundle = new GlideRecord('u_hardware_request_option');
        if (bundleSelected != 'none') {
            hardwareBundle.addQuery('u_bundle', bundleSelected);
            hardwareBundle.query();
        }

        var itemBundleName = [];
        var itemSysID = [];

        while (hardwareBundle.next()) {
            itemBundleName.push(hardwareBundle.u_hardware_name.toString());
            itemSysID.push(hardwareBundle.sys_id.toString());
        }

        return itemBundleName.toString() + '||' + itemSysID.toString();
    },
    type: 'findOptions'
});

did you check on PROD, if there is record in table ( u_hardware_request_option ) based on selected bundle. Assuming the code is exact same on Dev & PROD and Dev is returning the value but PROD doesn't. Check if read ACL (on u_hardware_request_option ) is restricting it.

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

I checked the read ACL on the u_hardware_request_option in PROD and it's the same as DEV. The u_hardware_request_option table is populated in PROD as well.