Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Parsing a JSON data to post in worknotes in incident

Abhijit Das7
Tera Expert

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

1 ACCEPTED SOLUTION

Not applicable

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();

View solution in original post

3 REPLIES 3

Not applicable

Hi @Abhijit Das7 

 

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

Hi @Community Alums ,

 

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

Not applicable

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();