Script include function not getting called from Catalog Client Script?

Jared Wason
Tera Guru

Hello,

I have a record producer with an onChange catalog client script. The catalog client script is using a glideAjax call to call my script include function. For some reason though it seems my function in the script include is never getting executed. I have minimalized the function as much as possible just to see if I can write to the log in the script include function, but I am getting nothing. I have verified that my naming and spelling of variables is correct. Does anyone see what I am doing wrong here?

 

find_real_file.pngfind_real_file.png

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Jared,

Try the following scripts. Executing these script should pop-up an alert with message 'OK'.

Things I've fixed:

  1. Set argument of process to 'answer'
  2. Directly output without using parsing because .getXMLAnswer() will return a string and not a xml. This implies there's no "answer[0]" nor "answer[1]" because answer is a String and not an array.
  3. Delete "initialize: function() {}," in Script Include. There's no initialize when it's Client Callable.

 

Client Script

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

   var adapiCall = new GlideAjax('ADAPICall');
	adapiCall.addParam('sysparm_name', 'getGroups');
	adapiCall.getXMLAnswer(process);
	
	function process(answer) {
		alert(answer);
	}
 }

Script Include

var ADAPICall = Class.create();
ADAPICall.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getGroups: function() {
        return 'OK';
    },
    type: 'ADAPICall'
});

 

View solution in original post

10 REPLIES 10

Hitoshi Ozawa
Giga Sage
Giga Sage

In case, to return an object with .getXMLAnswer(), use JSON.stringify() to convert an object to a JSON string.

e.g.

Script Include

var ADAPICall = Class.create();
ADAPICall.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getGroups: function() {
		var arr = [];
		arr.push('element1');
		arr.push('element2');
		var obj = {'fieldString': 'value1', 'fieldArray': arr};
        return JSON.stringify(obj);
    },
    type: 'ADAPICall'
});

Client Script

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

    var adapiCall = new GlideAjax('ADAPICall');
    adapiCall.addParam('sysparm_name', 'getGroups');
    adapiCall.getXMLAnswer(process);

    function process(answer) {
        if (answer) {
            var json = JSON.parse(answer);
			alert(json.fieldString);  // get value of variable "fieldString"
        }
    }
}