looping a JSON object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2018 07:11 AM
Hi,
Im trying to apply a loop for a json object and i don't know how to access to JSON element.
this is my code.
var ticketJson = {"type" : "Changement1" , "etat" : "Approuvé","epiclink": "URL","priorite" : "P1"};
//var obj = JSON.parse(ticketJson);
var item = this.newItem();
item.setAttribute('value', ticketJson);
var values = this.getParameter('sysparm_values').split(',');
for(var i in values){
var rec = new GlideRecord('u_tickets_jira');
rec.initialize();
rec.parent = taskID;
rec.u_change = taskID;
rec.u_type = values[i].type;
rec.u_etat = values[i].etat;
rec.insert();
}
the code market in red color doesn't work it does't return the value of "type" and "etat" existing in json object.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2018 02:07 AM
hello,
My problem is that i want to pass the values of "type", "etat", "epiclink" and "priorite" to a table and if i do for exemple:
for(var i in values){
var rec = new GlideRecord('u_tickets_jira');
rec.initialize();
rec.parent = taskID;
rec.u_change = taskID;
rec.u_type = values[i][type];
rec.u_etat = values[i][etat];
rec.insert();
}
this doesn't work.
and when im excuting gs.log(values[i][type],'test') to see what this return, it return undefined.
that's my problem.
Thanks.