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

asifnoor
Kilo Patron

Hi,

Can you print the value in the SI and check if you are getting the value or not.

 

I'm not getting gs.addInfoMessage('calling script include'); the message itself, not sure wheteher I'm calling script include correctly, also want to mention that it is in scoped app and I have made it available from all application scope

guruprasad1
Kilo Guru

Hi

Is the script include client callable?

Also, please put 'gs.log' or 'gs.info' in the script include to check whether control reached SI or not and for check logs

 

Regards

Guru

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