REST Error response parsing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2017 10:33 AM
Hi Everyone,
I am having an issue with rese api call ERROR parsing and getting a value out of it. any ideas how to get the error out put that I am seeing in the ecc queue.
I tried response.getErrorMessage() and also response.getBody() but no luck. I just want to get the output tag value in the screenshot.
Thanks
Sri

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2017 11:46 AM
Hello srinivas,
Lets see if I can help, but first could you please show the script you are using?
And what return value do you get from response.getBody()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2017 12:07 PM
You can check the below link to parse the xml response
XMLDocument Script Object - ServiceNow Wiki
You can write something like
var responseBody=response.getBody();
var xmldoc = new XMLDocument(responseBody, true);
gs.log(xmldoc.getNodeText("//Results/result/output"));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2017 01:17 PM
If you are on a version of ServiceNow prior to Jakarta, then RESTResponseV2 will only return a system generated "Method failed:... with code: 400" instead of the actual output. Here is a recent discussion of this behavior (including the HI server PRB and KB article): REST API to 3rd party system
It has been confirmed to be fixed in Jakarta. Alternatively, and/or in the mean time, you can query the ecc_queue table directly and parse the xml of the payload.