Script Include on Incident table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2024 12:13 PM
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'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2024 12:31 PM - edited ‎09-04-2024 12:31 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2025 01:35 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2025 01:37 PM
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.