Need Help to capture/fetch element from JSON response via ATF
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2025 03:19 AM
I am trying to fetch Incident number from JSON response and passing it to the next step step using ATF. I wrote below server side script, but it keeps giving error.
(function(outputs, steps, params, stepResult, assertEqual) {
var res= new GlideRecord("sys_atf_test_result_item");
res.addQuery('step','10a2d28283baee50bfb311b6feaad3ad');
res.orderByDesc("sys_updated_on");
res.setLimit(1);
res.query();
while(res.next()) {
var jsonresult=res.output;
var parsedJson = JSON.parse(jsonresult);
// Check if the parsed JSON has the incident number and extract it
if (parsedJson.hasOwnProperty('result') && parsedJson.result.length > 0) {
var incidentNumber = parsedJson.result[0].number; //'number' is a field in JSON response
outputs.record_id = incidentNumber;
gs.info("Incident number: " + outputs.record_id);
} else {
gs.info("Incident number not found in the response.");
}
}
})(outputs, steps, params, stepResult, assertEqual);
Can someone please help here?
Error :

Can someone please help here?
Error :
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2025 11:31 PM
Hi @Som4
such an error message appears whenever JSON.parse fails due to wrong JSON format. And the output field of the sys_atf_test_result_item table can contain everything and mostly it is plain text. So check first the data in that field before you continue.
Maik