Hi folks,
Long time since my last post. I always loved this forum because of all you guys and how you have helped me in the past. It's been a while since I put on my coding hat and now I am working in ServiceNow and trying to access a value within a REST response that is formatted as JSON.
Here is the JSON string I am trying to pull from:
I am trying to pull the value of the "display_value" and "sys_id" keys with the following code but when I test, the variables are blank:
I loaded the JSON into an online parser and did notice an additional level under the result key. Does this have to be specified in my code somehow?
I tried setting my "result" variable as follows:
But that threw an error "missing ; before statement".
I am stumped as to why these values are not populating. Any help is appreciated.
Thank you,
Ken
Long time since my last post. I always loved this forum because of all you guys and how you have helped me in the past. It's been a while since I put on my coding hat and now I am working in ServiceNow and trying to access a value within a REST response that is formatted as JSON.
Here is the JSON string I am trying to pull from:
JSON:
{"import_set":"ISET0156452","staging_table":"x_insmc_intapis_std_inbound_incident","result":[{"transform_map":"STD Inbound Incident","table":"incident","display_name":"number","display_value":"INC1540824","record_link":"https://somedevserver.service-now.com/api/now/table/incident/a636798cdb23a1105d34252b1396193d","status":"updated","sys_id":"a636798cdb23a1105d34252b1396193d"}]}
I am trying to pull the value of the "display_value" and "sys_id" keys with the following code but when I test, the variables are blank:
JavaScript:
(function execute(inputs, outputs) {
var responseBody = JSON.parse(inputs.response);
if(inputs.status!=201){
var errorMsg = responseBody.error.message;
var errorDetail = responseBody.error.detail;
throw "Error creating incident. Message: "+errorMsg + " Details:"+errorDetail;
} else {
var result = responseBody.result;
outputs.remote_incident_number = result.display_value;
outputs.remote_sys_id = result.sys_id;
}
})(inputs, outputs);
I loaded the JSON into an online parser and did notice an additional level under the result key. Does this have to be specified in my code somehow?
I tried setting my "result" variable as follows:
var result = responseBody.result.0;
But that threw an error "missing ; before statement".
I am stumped as to why these values are not populating. Any help is appreciated.
Thank you,
Ken