script include and client script makes problem for set a value in description

Amandeep39
Tera Contributor

I tried to get the number, priority, and short description value entered in the description field when I made changes in the existing incident's caller field. The for loop does not get all incident details after parsing it. Can anyone help me fix this error?  alert(obj) shows a null value.

 

Script includes:

var getIncDetails1 = Class.create();
getIncDetails1.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getInc: function() {
        var inArray = [];
        var gr = new GlideRecord('incident');
        gr.addQuery('caller_id', this.getParameter('sysparm_value'));
        gr.query();
        while (gr.next()) {
            var incDetails = {};
            incDetails.number = gr.number.toString();
            incDetails.priority = gr.priority.getDisplayValue();
            incDetails.short_desc = gr.short_description.toString();
            incArray.push(incDetails);

            /*Example:-
            {
                "number": "INC000256",
                "priority": "2-High",
                "short_desc": "This is descritpion"
            }; {
                "number": "INC000256",
                "priority": "2-High",
                "short_desc": "This is descritpion"
            };
            n number of records based on caller created
            */

        }    
    return JSON.stringify(inArray);
    },
    type: 'getIncDetails1'
});

I made a client script: 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var finalArray = [];
    var ga = new GlideAjax('getIncDetails1');
    ga.addParam('sysparm_name', 'getInc');
    ga.addParam('sysparm_value', g_form.getValue('caller_id'));
    ga.getXMLAnswer(IncDetail);
   
    function IncDetail(response) {
        var obj = JSON.parse(response);
        alert(obj);
        for (var i = 0; i < obj.length; i++) {
            alert("Incident Number: "+ obj[i].number);
            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);
    }
}
1 ACCEPTED SOLUTION

Mohammed8
Mega Sage

Hi @Amandeep39 

at start of your script i see this issue .

pushing data into an undefined array incArray but  you have used inArray

Mohammed8_0-1765961050614.png

 

Regards,

Mohammed Zakir

View solution in original post

2 REPLIES 2

Mohammed8
Mega Sage

Hi @Amandeep39 

at start of your script i see this issue .

pushing data into an undefined array incArray but  you have used inArray

Mohammed8_0-1765961050614.png

 

Regards,

Mohammed Zakir

Ankur Bawiskar
Tera Patron
Tera Patron

@Amandeep39 

point mentioned by @Mohammed8 is valid.

please update the array name in script and it will work fine

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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