Calling Script Include from catalog client script

chidanandadhath
Kilo Guru

I have below Catalog client script which calls the script include. I'm getting the answer as null

function onChange(control, oldValue, newValue, isLoading) {
	
	if(newValue == oldValue) {
		return;
	}
	var answer_json = [];
	var gaj = new GlideAjax('x_113476_managed_c.getCiClass');
	gaj.addParam('sysparm_name','getPrimaryCiClass');
	gaj.getXML(ajaxResponse);
	function ajaxResponse(response) {
		var answer = response.responseXML.documentElement.getAttribute("answer");
		alert(answer);
		if(answer) {
			answer_json = answer.evalJSON();
			//alert(answer_json);
		}
		
	}
	
	var collectorName = 'CIs';
	var filterString = 'sys_class_nameIN'+answer_json;
	
	try{
		var myListCollector = g_list.get(collectorName);
		myListCollector.reset();
		myListCollector.setQuery(filterString);
	}
	
	catch(e){
		
		window[collectorName + 'g_filter'].reset();
		window[collectorName + 'g_filter'].setQuery(filterString);
		window[collectorName + 'acRequest'](null);
	}
}
//}

Script include

var getCiClass = Class.create();
getCiClass.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	
	initialize: function() {
	},
	
	getPrimaryCiClass : function()
	{
		gs.addInfoMessage('calling script include');
		var strCiClass = '';
		var arrConfigItemClass = [];
		var grPrimaryCiClass = new GlideRecord('x_113476_managed_c_managedciclass');
		grPrimaryCiClass.addActiveQuery();
		grPrimaryCiClass.addQuery('primary_ci_class',true);
		grPrimaryCiClass.query();
		while (grPrimaryCiClass.next())
			{
			strCiClass = grPrimaryCiClass.ci_class;
			arrConfigItemClass.push(strCiClass.toString());
			
			
		}
		return arrConfigItemClass;
	},
	
	type: 'getCiClass'
});
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

remove initialize() function from that client callable script; it is not required; remove this and it should work

If you want to make a script "Client callable", you can't have "initialize" function.

initialize: function() { },

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

I'm getting the output as org.mozilla.javascript.NativeArray@1750d6e when logged

I see arrConfigItemClass is an array. Try returning it as a String to the client side. Either use JSON to stringify it or maybe just join the array with "," before returning:

 

return arrConfigItemClass.join(",")

Mike Patel
Tera Sage

try doing 

return arrConfigItemClass.toString();

I got the output, did the same.... I want to apply same to the filter..

chidanandadhath
Kilo Guru

find_real_file.png