How to parse soap xml response

Rahul RJ
Giga Sage
Giga Sage

Hi Friends,

I have done remedy to ServiceNow integration using soap web service, Having problem to parse XML response and setting the incident number to ServiceNow custom field named remedy incident number.

soap xml response

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns0:HelpDesk_Submit_ServiceResponse
xmlns:ns0="urn:COL_HPD_IncidentInterface_Create_WS"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns0:Incident_Number>INC000000121114</ns0:Incident_Number>
</ns0:HelpDesk_Submit_ServiceResponse>
</soapenv:Body>
</soapenv:Envelope>

 

Tried XML parsing in the Business rule but no luck

var xmlDoc = new XMLDocument();
xmlDoc.parseXML(responseBody);
var correlationID = xmldoc.getNodeText("//ns0:Incident_Number");

find_real_file.png

1 ACCEPTED SOLUTION

Bhawana Upreti
Tera Guru
Hi,

Can you try the given script in your business rule.

var response = s.execute();
var ResponseBody = response.getBody();
var status = response.getStatusCode();
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(ResponseBody);
var correlationID = xmlDoc.getNodeText("//ns0:Incident_Number");
gs.log(correlationID);

Thanks

View solution in original post

9 REPLIES 9

Gaurav Bajaj
Kilo Sage

Hi,

Did you try to parse it using XMLDocument2 instead of XMLDocument?

https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

Gajanan Birada1
Giga Expert

Hi,

You are not getting  data in xml format first you have convert that data into XML format  ,because I can see

object as a response.

You can do first that response data in stringformat if it is getting then you can parse it.

JSON.stringify(); there is method you can use that method.

then write your script.

var xmlDoc = new XMLDocument();
xmlDoc.parseXML(responseBody);
var correlationID = xmldoc.getNodeText("//ns0:Incident_Number");

Thank You

Gajanan Biradar

Bhawana Upreti
Tera Guru
Hi,

Can you try the given script in your business rule.

var response = s.execute();
var ResponseBody = response.getBody();
var status = response.getStatusCode();
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(ResponseBody);
var correlationID = xmlDoc.getNodeText("//ns0:Incident_Number");
gs.log(correlationID);

Thanks

Thanks Bhawana it's working for me