- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 05:36 AM
Hi Everyone,
I am creating Scripted REST API to get data from JSON to Incident work notes.
JSON payload :
{
"data": [
{
"type" : "line",
"Name" : "Ravi"
},
{
"type":"multiline",
"Address" : "XYZ"
},
{
"type":"radioButton",
"Gender":"Male",
}
]
Can anyone guide me how can I use this array to post this data to work notes in incident. In each object of array has two fields :
1. Type
2. Second field can be anything Name , Address , Gender , email, phone etc.
I am facing difficult in using second field which is dynamic.
Thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 06:43 AM
Hi,
Below is the script to get dynamic keys from your JSON.
var obj = { "data": [
{
"type" : "line",
"Name" : "Ravi"
},
{
"type":"multiline",
"Address" : "XYZ"
},
{
"type":"radioButton",
"Gender":"Male",
}
]};
for(var i=0;i<obj.data.length;i++){
var obj1 = obj.data[i];
for(key in obj1){
gs.info("key is "+key+" and value is "+obj1[key]);
}
}
you can use above logic to extract the values as per your requirement
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2024 10:11 PM
Try as below :
var Submission = parsedData.submission;
var WorkNotes = '';
for (var t = 0; t < Submission.length; t++) {
var obj1 = Submission[t];
for (key in obj1) {
str = key + ' : ' + obj1[key] + '\n';
gs.info(str);
WorkNotes+= str;
}
}
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2024 09:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2024 10:11 PM
Try as below :
var Submission = parsedData.submission;
var WorkNotes = '';
for (var t = 0; t < Submission.length; t++) {
var obj1 = Submission[t];
for (key in obj1) {
str = key + ' : ' + obj1[key] + '\n';
gs.info(str);
WorkNotes+= str;
}
}
Please mark this response as correct and helpful if it assisted you with your question.