REST Error response parsing

sgc
Giga Contributor

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.

find_real_file.png

Thanks

Sri

3 REPLIES 3

mak1A4
Tera Guru

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


ark6
Mega Guru

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


Robert Beeman
Kilo Sage

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.