Getting "[object Object] - undefined - undefined" as output in the desired field

Community Alums
Not applicable

Hi All,

 

I have written script to fetch data from script include but in desired field getting output as "[object Object] - undefined - undefined". what would be the mistake?. PFB output screenshot, script include and client script respectively.

find_real_file.png

Script Include - 

IsEscalate: function() {
        gs.log("enter into 6 line");
        var task1 = this.getParameter('sysparm_oas');//.toString();
        var scTask = new GlideRecord('sc_task');
        scTask.addQuery('request_item', task1);
        //scTask.addQuery('state', 1);
        //scTask.addQuery('stateIN-5,1,2');
        scTask.query();
        var arr =[];
        
        gs.log("Enter into line 11");
        while (scTask.next()) {
            var obj = {};
            gs.log("enter into 12 line");
            obj.agm = scTask.getDisplayValue('assignment_group.manager').toString();
            obj.ag = scTask.getDisplayValue('assignment_group').toString();
            obj.scn = scTask.number.toString();
            arr.push(obj);
            gs.log("Hello");
        }
        gs.log("enter into 20 line");
        var data = JSON.stringify(arr);
        gs.log("enter into 23 line");
        gs.log("Test"+obj);
        return data;
        //gs.log("Hi");
        },

Client Script - 

function onSubmit() {
    var a = g_form.getUniqueValue();
    var ga = new GlideAjax('EscalatedScTask');
    ga.addParam('sysparm_name', 'IsEscalate');
    ga.addParam('sysparm_oas', a);
    ga.getXMLWait();
    alert('Sys id is ' + a);
    alert("line 7");
    var arr = JSON.parse(ga.getAnswer());
    alert("line 9");
    alert(arr);
    g_form.setValue('u_escalation_owner_assignment_group_sctask', arr[0] + " - " + arr[1] + " - " + arr[2]);
    alert("line 11");
}

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

hello,

while sending the JSON replace like below 

return JSON.stringify(data);

And while accessing it you need to do like below 

   var arr = JSON.parse(ga.getAnswer());
   
    g_form.setValue('u_escalation_owner_assignment_group_sctask', arr[0].agm + " - " + arr[0].ag + " - " + arr[0].scn);

MARK MY NASWER CORRECT IF THIS HELPS YOU

View solution in original post

17 REPLIES 17

Community Alums
Not applicable

Hi Mohith,

But one issue is if Multiple tasks are open on RITM the attached output we are getting (If one task is there it is working correct), what would be the issue?

 

The field details are 

String type with length 4000

palanikumar
Giga Sage

Hi,

You'll get proper output only if 3 Catalog Tasks are attached to the RITM. Can you check whether the RITM you were referring has 3 task attached?

Thank you,

Palani

Thank you,
Palani

Muhammad Khan
Mega Sage
Mega Sage

You are using obj outside its scope in this gs.log("Test"+obj); because obj is declared inside while loop. So, use below scripts.

 

Script Include - 

IsEscalate: function() {

        var task1 = this.getParameter('sysparm_oas');
        var scTask = new GlideRecord('sc_task');
        scTask.addQuery('request_item', task1);
        scTask.query();
        var arr =[];
        
        while (scTask.next()) {
            var obj = {};
            gs.log("enter into 12 line");
            obj.agm = scTask.assignment_group.manager.getDisplayValue();
            obj.ag = scTask.assignment_group.getDisplayValue();
            obj.scn = scTask.number.toString();
            arr.push(obj);
        }

        var data = JSON.stringify(arr);
        return data;
        },

 

Client Script - 

function onSubmit() {
    var a = g_form.getUniqueValue();

    var ga = new GlideAjax('EscalatedScTask');
    ga.addParam('sysparm_name', 'IsEscalate');
    ga.addParam('sysparm_oas', a);


    ga.getXMLWait();

    var arr = JSON.parse(ga.getAnswer());

 

    // You might have to loop through if you have an array of objects, and use the as per your requirements.
    g_form.setValue('u_escalation_owner_assignment_group_sctask', arr[0].agm + " - " + arr[0].ag + " - " + arr[0].scn);

}