- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 02:50 AM - edited 03-21-2024 03:58 AM
Hi Everyone,
I have JSON data which I have to parse and post in work notes of incident.
JSON:
{
"incident_sys" : "ff4c21c4735123002728660c4cf6a758",
"table_name" : "incident",
"field 0": {
"type": "singleLine",
"Name": "Testing Testing"
},
"field 1": {
"type": "multiLine",
"Address": "Testing Testing Testing"
},
"field 2": {
"type": "dropDown",
"Gender": "Male"
},
"field 3": {
"type": "radioButton",
"Qualification": "PG"
},
"field 4": {
"type": "checkBox",
"Hobbies": [
{
"Playing": "1"
},
{
"Gardening": "1"
},
{
"Listening Music": "1"
},
{
"Singing": "0"
},
{
"Trekking": "1"
}
]
},
"field 5": {
"type": "rating",
"Rates Us": "5"
},
"field 6": {
"type": "thumbRating",
"Are you satisfied with us?": "1"
},
}
Expected Output:
Name : Testing Testing
type : singleLine
Address : Testing Testing Testing
type : multiLine
Qualification : UG
type : dropDown
Gender : Male
type : radioButton
Hobbies :
Playing : 1
Gardening : 1
Listening Music : 1
Singing : 0
type : checkBox
Rates us : 5
type : rating
Are you satisfied with us? : 1
type : thumbRating
Can anyone guide me populate this incident work notes.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 04:33 AM
You can modify it-
var form = jsonData.form;
var workNotes = '';
for (var key in form) {
if (form.hasOwnProperty(key) && typeof form[key] === 'object') {
var field = form[key];
workNotes += key + ' :\n';
for (var prop in field) {
if (field.hasOwnProperty(prop) && prop !== 'type') {
workNotes += prop + ' : ' + field[prop] + '\n';
}
}
workNotes += 'type : ' + field.type + '\n\n';
}
}
current.work_notes = workNotes;
current.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 03:27 AM
Can you try this approach-
var form = jsonData.form; // hope JSON data is stored in a variable named jsonData
var workNotes = '';
for (var key in form) {
if (form.hasOwnProperty(key)) {
var field = form[key];
workNotes += key + ' :\n';
for (var prop in field) {
if (field.hasOwnProperty(prop) && prop !== 'type') {
workNotes += prop + ' : ' + field[prop] + '\n';
}
}
workNotes += 'type : ' + field.type + '\n\n';
}
}
current.work_notes = workNotes;
current.update();
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 04:02 AM
Hi @Amit Pandey ,
There is slight change in JSON , can you please suggest something now please.
Basically, above JSON has fields which store string i.e, incident_sys , table_name , etc which I have ignore and there are some fields which are object i.e, field 0 , field1, field2 ... etc which I have to paste in work notee of incident record.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 04:33 AM
You can modify it-
var form = jsonData.form;
var workNotes = '';
for (var key in form) {
if (form.hasOwnProperty(key) && typeof form[key] === 'object') {
var field = form[key];
workNotes += key + ' :\n';
for (var prop in field) {
if (field.hasOwnProperty(prop) && prop !== 'type') {
workNotes += prop + ' : ' + field[prop] + '\n';
}
}
workNotes += 'type : ' + field.type + '\n\n';
}
}
current.work_notes = workNotes;
current.update();