Calling Script Include from Catalog client script

vidhya_mouli
Giga Sage

I am having an issue in calling a script include:

Catalog Client Script:

 

 

var TotalSmsGA = new GlideAjax('EmploymentUtils');
TotalSmsGA.addParam('sysparm_name', '_getTotalSMS');
TotalSmsGA.getXML(getSMSLength);

function getSMSLength(response) {
var test = response.responseXML.documentElement.getAttribute("answer");
console.log(test);
}

 

 


Script Include:

 

 

_getTotalSMS: function() {
return '100';
},

 

 

 

SI is client callable.
I am getting the result as null. Any suggestions for what is wrong here?

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @vidhya_mouli,

 

Use the following tried and tested on my PDI (leveraging a random onLoad Client Script and Cat Item):

I'm alerting the result of 100 so you can confirm it's working. You'll just need to assign that to whatever variable or use appropriately for your use case.

 

Client Script:

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }


    var TotalSmsGA = new GlideAjax('EmploymentUtils');
    TotalSmsGA.addParam('sysparm_name', 'getTotalSMS');
    TotalSmsGA.getXML(getSMSLength);

    function getSMSLength(response) {
        var test = response.responseXML.documentElement.getAttribute("answer");
        alert(test);
    }

}

 

 

 

Script Include:

 

 

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

	
    getTotalSMS: function() {
        return '100';
    },

    type: 'EmploymentUtils'
});

 

 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.

 

Thanks, Robbie

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Try a function name without the leading _ / special character.  Do you happen to have more than one SI with the same name?  Is the SI in the same application/scope as the Catalog Item / Catalog Client Script? If not, use the scope name in the GA call:

var TotalSmsGA = new GlideAjax('global.EmploymentUtils');

AshishKM
Kilo Patron
Kilo Patron

try without "_"  

getTotalSMS

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

Robbie
Kilo Patron
Kilo Patron

Hi @vidhya_mouli,

 

Use the following tried and tested on my PDI (leveraging a random onLoad Client Script and Cat Item):

I'm alerting the result of 100 so you can confirm it's working. You'll just need to assign that to whatever variable or use appropriately for your use case.

 

Client Script:

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }


    var TotalSmsGA = new GlideAjax('EmploymentUtils');
    TotalSmsGA.addParam('sysparm_name', 'getTotalSMS');
    TotalSmsGA.getXML(getSMSLength);

    function getSMSLength(response) {
        var test = response.responseXML.documentElement.getAttribute("answer");
        alert(test);
    }

}

 

 

 

Script Include:

 

 

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

	
    getTotalSMS: function() {
        return '100';
    },

    type: 'EmploymentUtils'
});

 

 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.

 

Thanks, Robbie