Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
Hi All
The code below (with some details starred out for confidentiality) is intended to get a property of a JSON message and display it as a column in an InfoTable. I have attempted to gain the description property from the following JSON and display it in an infoTable for output:
JSON:
{"tickets":[{"raw_subject":"Compressor Ticket #1","subject":"Compressor Ticket #1","custom_fields":[],"created_at":"2015-08-12T07:28:08Z","description":"Ticket for compressor - API123456","submitter_id":*******,"type":"problem","priority":"normal","collaborator_ids":[],"url":"**********","via":{"channel":"api","source":{"from":{},"to":{}}},"tags":[],"brand_id":******,"updated_at":"2015-08-12T09:05:32Z","sharing_agreement_ids":[],"group_id":********,"organization_id":********,"id":4.0,"has_incidents":false,"fields":[],"assignee_id":**********,"status":"open","requester_id":********}],"count":1.0}
JavaScript:
var params = {
infoTableName: "infoTable" /* STRING */,
dataShapeName: "*******" /* DATASHAPENAME */
};
// result: INFOTABLE
var infoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
var params = {
ignoreSSLErrors: true /* BOOLEAN */,
url: "*********" /* STRING */,
timeout: 30 /* NUMBER */,
password: "******" /* STRING */,
username: "******" /* STRING */
};
// result: JSON
var response = Resources["ContentLoaderFunctions"].LoadJSON(params);
var row = new Object();
row.description = response.tickets.description;
infoTable.AddRow(row);
var result = infoTable;
The problem I am having is that when I execute this the output is an infotable with the "description" field blank. I have tried doing a JSON.parse on my response but this return an error which I believe means that the JSON message has already been formatted into an object.
Can someone please point out what I am doing wrong and why row.description = response.tickets.description; doesn't work on the JSON message?
Any feedback would be highly appreciated.
Many thanks
Ashley
I believe response.description should do the trick.