Issue with the client script or script include.

Spike236
Tera Contributor

Hello folks,

 

i have created a catalog client script and script include to count related items for the value on the picked variable and based on the number, make variable2 visible or not. I have changed the script include to return number two for testing purposes, however its returning null. That makes me to believe that there is an issue with the logic. However,

I dont know where the issue is. Grateful for any help!

 

Script include

 

var Utils = Class.create();
Utils .prototype = {
    initialize: function() {},
    getCount: function() {
        var pSysId = this.getParameter('sysparm_SysId');

        var progGR = new GlideRecord('table');
        progGR .addQuery('port', pSysId );
        progGR .addQuery('pro.active', true);
        progGR .addQuery('prote', gs.getProperty('property_name'));
        progGR .setLimit(2);
        progGR .query();
        return '2'; //progGR .getRowCount();
    },
    type: 'Utils '
};

 

catalog client script

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var UtilsAJAX = new GlideAjax('utils');
    UtilsAJAX .addParam('sysparm_name', 'getCount');
    UtilsAJAX .addParam('sysparm_SysId', g_form.getValue('variable1'));
    UtilsAJAX.getXML(function(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        if (answer === '2') {
            g_form.setDisplay('prog', true);
        } else {
            g_form.setDisplay('prog', false);
        }

        g_form.addInfoMessage(answer);
    });
}

 

 

1 ACCEPTED SOLUTION

Marco0o1
Tera Sage

Hi @Spike236 ,

 

That looks you dont create you element ass Client callable, if you dont select that tag you cant call your script include from a script, first you need to tag the client callable and make some changes:

Marco0o1_0-1694460034605.png

 

var Utils = Class.create();

Utils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getCount: function() {
        var pSysId = this.getParameter('sysparm_SysId');

        var progGR = new GlideRecord('table');
        progGR .addQuery('port', pSysId );
        progGR .addQuery('pro.active', true);
        progGR .addQuery('prote', gs.getProperty('property_name'));
        progGR .setLimit(2);
        progGR .query();
        return '2'; //progGR .getRowCount();
    },
    type: 'Utils '
});

 

Then you call your function, just make sure is called with the exactly same name you created in your script include:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var UtilsAJAX = new GlideAjax('Utils'); //Make sure is writing in the same method you create in your Script Inclide, capital letters are diferents
    UtilsAJAX .addParam('sysparm_name', 'getCount');
    UtilsAJAX .addParam('sysparm_SysId', g_form.getValue('variable1'));
    UtilsAJAX.getXML(function(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        if (answer === '2') {
            g_form.setDisplay('prog', true);
        } else {
            g_form.setDisplay('prog', false);
        }

        g_form.addInfoMessage(answer);
    });
}

 

Hope that help you

View solution in original post

5 REPLIES 5

jaheerhattiwale
Mega Sage
Mega Sage

@Spike236 To use the script include in the GlideAjax, it should be client callable.

jaheerhattiwale_0-1694491237898.png

The client callable checkbox should be true and the script should have the code as shown in image above. (the code is missing in your code)

 

 

And you need to pass the correct name of script include in the GlideAjax. (You have used the script include name as utils but defined the script include as Utils)

 

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023