
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2024 08:42 AM
Please help to get each output value from below script.
{"categoryKey":"BR Ordering|Customer|abc","recentIncidents":[{"number":"INC4449296","sys_id":"8422274f1bd80210"},{"number":"INC4449297","sys_id":"2da2e34f1bd802106"}],"historicIncidents":[{"number":"INC4449127","sys_id":"494c610c1b480a10"},{"number":"INC4449130","sys_id":"fafda14c1b040a508"},{"number":"INC4449296","sys_id":"8422274f1bd802106"},{"number":"INC4449297","sys_id":"2da2e34f1bd80210"}]}
It should print output as below
category is : BR Ordering|Customer|abc
Recent Incident are : INC4449296 , INC4449297
Historic Incidents are : INC4449127,INC4449130,INC4449296,INC4449297
Regards,
Nikki
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2024 09:30 AM
Hi @Community Alums ,
Try the code I have pasted below.
var payload = {"categoryKey":"BR Ordering|Customer|abc","recentIncidents":[{"number":"INC4449296","sys_id":"8422274f1bd80210"},{"number":"INC4449297","sys_id":"2da2e34f1bd802106"}],"historicIncidents":[{"number":"INC4449127","sys_id":"494c610c1b480a10"},{"number":"INC4449130","sys_id":"fafda14c1b040a508"},{"number":"INC4449296","sys_id":"8422274f1bd802106"},{"number":"INC4449297","sys_id":"2da2e34f1bd80210"}]};
var category = payload.categoryKey;
var recentIncidentNum= [];
var recentIncidents = payload.recentIncidents;
for(i=0; i < recentIncidents.length; i++){
recentIncidentNum.push(recentIncidents[i].number.toString());
}
var historicIncidentNum = [];
var historicIncident = payload.historicIncidents;
for(j=0; j < historicIncident.length; j++){
historicIncidentNum.push(historicIncident[j].number.toString());
}
gs.info("Category is :"+ category);
gs.info("Recent Incidents are :"+ recentIncidentNum);
gs.info("Historic Incidents are :"+ historicIncidentNum);
Output:
Script: Category is :BR Ordering|Customer|abc
*** Script: Recent Incidents are :INC4449296,INC4449297
*** Script: Historic Incidents are :INC4449127,INC4449130,INC4449296,INC4449297
Please mark as helpful and accept as solution, if you found this code useful.
Regards,
Dhanraj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2024 09:04 AM
Hi @Community Alums ,
Can u try something like below.
Lets say u r storing that JSON value in
var jsonOutput = "that JSON value";
var resultOutput= JSON.parse(jsonOutput);
gs.info("category is : " +resultOutput.categoryKey + '\n'+ "Recent Incidents are :"+ resultOutput.recentIncidents + '\n'+ "Historic Incidents are :"+resultOutput.historicIncidents);
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2024 09:30 AM
Hi @Community Alums ,
Try the code I have pasted below.
var payload = {"categoryKey":"BR Ordering|Customer|abc","recentIncidents":[{"number":"INC4449296","sys_id":"8422274f1bd80210"},{"number":"INC4449297","sys_id":"2da2e34f1bd802106"}],"historicIncidents":[{"number":"INC4449127","sys_id":"494c610c1b480a10"},{"number":"INC4449130","sys_id":"fafda14c1b040a508"},{"number":"INC4449296","sys_id":"8422274f1bd802106"},{"number":"INC4449297","sys_id":"2da2e34f1bd80210"}]};
var category = payload.categoryKey;
var recentIncidentNum= [];
var recentIncidents = payload.recentIncidents;
for(i=0; i < recentIncidents.length; i++){
recentIncidentNum.push(recentIncidents[i].number.toString());
}
var historicIncidentNum = [];
var historicIncident = payload.historicIncidents;
for(j=0; j < historicIncident.length; j++){
historicIncidentNum.push(historicIncident[j].number.toString());
}
gs.info("Category is :"+ category);
gs.info("Recent Incidents are :"+ recentIncidentNum);
gs.info("Historic Incidents are :"+ historicIncidentNum);
Output:
Script: Category is :BR Ordering|Customer|abc
*** Script: Recent Incidents are :INC4449296,INC4449297
*** Script: Historic Incidents are :INC4449127,INC4449130,INC4449296,INC4449297
Please mark as helpful and accept as solution, if you found this code useful.
Regards,
Dhanraj.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 01:51 AM
Hi Dhanraj, Thank you! This helped me to get each values.