Client Script Returning Null

ManishS14752344
Tera Contributor

Hi,

So I have this combination of onChange client script and script include

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || !newValue) return;

    var ga = new GlideAjax('AccountSTOChecker');
    ga.addParam('sysparm_name', 'checkStoreOrder');
    ga.addParam('sysparm_account_id', newValue);

    ga.getXMLAnswer(function (answer) {

        if (answer === null) {
            console.error('GlideAjax returned NULL - Script Include not reachable');
            return;
        }

        console.log('Account STO Type stored:', answer);

        sessionStorage.setItem('accountSTOType', answer);

        if (answer === 'true') {
            g_form.addInfoMessage('STO Account - attachment required');
        }
    });
}



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

    checkStoreOrder: function () {
        var accountId = this.getParameter('sysparm_account_id');

        if (!accountId)
            return 'false';

        var acc = new GlideRecord('customer_account');
        if (!acc.get(accountId))
            return 'false';

        var type = acc.getValue('u_so_sto');

        if (type == '2') {
            return 'true';
        }

        return 'false';
    },

    type: 'AccountSTOChecker'
});

The answer is returning in null and I cannot figure out why.
2 REPLIES 2

Brad Bowman
Kilo Patron

Good job with the Client Script logs.  If you are getting an unexpected 'answer' add some logs to the Script Include to confirm that it is running and to see how far it gets.  If you determine it's not running, ensure it is in the same Application/scope as the Client Script and the form/Catalog Item it is called on, or else use the full API Name in the GlideAjax call.  Also make sure there are not any other Script Includes with the same name.  Did you add a role/access control to the Script Include?  Is there anything helpful in the browser console or system logs?

Hi @Brad Bowman  ,

Thanks for replying. So I was thinking that the script include might be having some issue so I tried calling it from a background script and it returns the answer as expected. But when I try to call it from my catalog client script, it is always returning null. 

About the scope, I have made sure both my script include and the record producer are in the same scope.