Script Include on Incident table

SnowDevOps
Giga Guru

Hello Team,

I'm trying to write a script include & client script for this requirement. On the incident form, when the user changes to a different caller name, It should show all the incidents that are raised by the caller and it should display that in the Description field. I looked at my scripts, and everything seemed right. It didn't do anything when i tested. Thanks for your help. 

Here is my client script:

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

	var finalArray = [];
	var ga = new GlideAjax('getIncDetail');
	ga.addParam('sysparm_name', 'getInc');
	ga.addParam('sysparm_user_id', g_form.getValue('caller_id'));
	ga.getXMLAnswer(IncDetail);

	function IncDetail(response) {
		
		var obj = JSON.parse(response);
		for (var i = 0; i < obj.length; i++) {
			finalArray.push('Incident Number: '+obj[i].number +'\n' +'Priority: '+obj[i].priority +'\n' +'Short Description: '+obj[i].short_desc+'\n');
		}
		g_form.setValue('description', finalArray);
	}
   
}

Here is my script include

var getIncDetail = Class.create();
getIncDetail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	getInc: function () {
		var inArray = [];
		var gr = new GlideRecord('incident');
		gr.addQuery('caller_id', this.getParameter('sysparm_user_id'));
		gr.query();
		while (gr.next()) {
			var incDetail = {};
			incDetail.number = gr.number.toString();
			incDetail.priority = gr.priority.getDisplayValue();
			incDetail.short_desc = gr.short_description.toString();
			inArray.push(incDetail);
		}
		return JSON.stringify(incArray);
	},
    type: 'getIncDetail'
});

 

3 REPLIES 3

Zach Koch
Giga Sage
Giga Sage

I would start by adding an alert(finalArray.join(',')) in your response function, and see what Ajax call is returning at the very end, then work your way backwards to find out where the script is failing, client side, or in the script include.

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

k_ry
Tera Contributor

Hope this issue was resolved, if not, there is typo in the array name, you have declared it as inArray and while converting to JSON String, it says incArray. 

k_ry
Tera Contributor

I hope this issue is resolved. 

There is typo in the declaration of the array - inArray and while converting to JSON you have it as incArray.