GlideAjax not working in client script

Ahmad6
Giga Expert

Hi guys,

 

I've tried to follow the guide at https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f96196e to create a client script which uses script include but the script is not accessing the script include (or i'm not reading the data correctly). I have used this process in other Client scripts in slightly different manners and they work fine so i'm not sure what's happening, if I can get another set of eyes that would be greatly appreciated.

The table inherits the incident table, and uses a matrix of category/subcategory to determine the priority/SLA duration.

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

	var ga = new GlideAjax('AL_SCRIPT');
	ga.addParam('sysparm_name','getPriority');
	ga.addParam('sysparm_category', g_form.getValue('category'));
	ga.addParam('sysparm_subcategory', g_form.getValue('subcategory'));
	ga.getXML(parseAjax);
	
}

function parseAjax(response) {
	var answer = response.responseXML.documentElement.getAttribute("answer");
	g_form.addInfoMessage('priority: ' + answer);
	if(answer){		
		g_form.setValue('priority',answer);
	}
	
}

script include below:

var AL_SCRIPT = Class.create();
AL_SCRIPT.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	getPriority:  function () {
	gs.addInfoMessage("finding priority");
	var category = this.getParameter('sysparm_category');
	var subcategory = this.getParameter('sysparm_subcategory');
	
	var gr = new GlideRecord('u_ncr_matrix');
	gr.addQuery('u_category', category);
	gr.addQuery('u_subcategory', category);
	gr.query();
	if(gr.next()){
		return gr.u_priority;
	} else return false;
},


type: 'AL_SCRIPT'
});
1 ACCEPTED SOLUTION

Brent Sutton
Mega Sage

Might be a silly question but have you checked that "Client callable" is ticked on your script include?

find_real_file.png

View solution in original post

28 REPLIES 28

sachin_namjoshi
Kilo Patron
Kilo Patron

g_form.addInfoMessage will not work in client script.

Please use  alert('priority: ' + answer);

 

Regards,

Sachin

Hi Sachin,

 

It definitely works, unless you mean that I cannot properly display what is contained in answer with that message. I removed the first g_form.addInfoMessage in the above script, as it was just to confirm that I was using the correct field.

 

find_real_file.png

Yes, addInfoMessage does workon Client. Can you try debugging by using alert at client level , what value you are passing and getting as answer ? If object is returned use gr.getValue instead.

Also, by chance did you rename your scriptinclude function name of SI itself. If so it doesn't work properly in such cases. Try creating a new one, it will work.

 

Thanks

Kushagra

Hi Kushagra, 

 

As per the screenshot I have printed the data that I am passing into the script, and it shows the correct string value is being passed in to the addParam functions.

the script include is called "AL_SCRIPT", and it was a new script that I created. What I think the issue might be is related to the structure in how I've created the script include.