
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 03:24 AM
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.
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");
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 03:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 03:27 AM
Hi,
In previous question was it working ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 03:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 05:37 AM
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());
g_form.setValue('u_escalation_owner_assignment_group_sctask', arr[0].agm + " - " + arr[0].ag + " - " + arr[0].scn);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 03:29 AM
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