Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Parse SOAP xml response

Vineetha Rohra1
Giga Guru

Hi All,

How do i parse an xml response that i get from soap message ?

I want the sys_id from the response.

EX- i got a following response:

<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body><insertResponse xmlns="http://www.service-now.com/u_fetch_incidents_19057"><sys_id>62c20f0edb222200d17ad6fdbf9619d5</sys_id><table>incident</table><display_name>number</display_name><display_value>ABC0010111</display_value><status>inserted</status></insertResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

I want the value of the sys id that i have highlighted to be used ahead in my code.

1 ACCEPTED SOLUTION

Mohammed_Iqbal
Tera Guru

Hello Vineetha Rohra,

 I have store your response in one field and written business rule according to your requirement its working fine.

script:--

var res=current.getValue('u_response');
    
var xmlDoc = new XMLDocument2();

xmlDoc.parseXML(res);//you can user response body here.


 var num = xmlDoc.getNodeText('//sys_id');//here you write whta you want from response.


    gs.addInfoMessage(num);

 

find_real_file.png

 

HOPE THIS HELPFUL!!!!! MARK CORRECT OR HELPFUL.

Thanks,
Mohammed Iqbal


   

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Vineetha,



Not sure whether you found answer for your question, but here is the way to fetch the value for sys_id tag value from the xml by xml parsing



var xmlString = ''; // your xml string which is soap response


var xmldoc = new XMLDocument();


gs.print("Sys id is:"+xmldoc.getNodeText("//insertResponse/sys_id"));



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

shailesh1729
Tera Expert

I'm facing the same issue with below response.

 

---------------------------------------------------


<?xml version="1.0" encoding="UTF-8"?>
<ServiceIncident xmlns="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2" xmlns:m1="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2" xmlns:m3="http://www.ibm.com/maximo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RequesterID>IN10003273</RequesterID>
<ProviderID>INC0376178</ProviderID>
<Transaction><Acknowledge>1</Acknowledge>
<StatusCode>0</StatusCode>
<Comment>Success - No Errors Encountered</Comment>
<TransactionName>Problem_Submittal</TransactionName>
<TransactionType>2</TransactionType>
<TransactionDateTime>2016-09-14T01:46:55Z</TransactionDateTime>
<TransactionNumber/>
<TransactionRouting>MX::AIAICDSNINC</TransactionRouting>
</Transaction>
</ServiceIncident>

===================================

I need RequesterID from above.

var xmlDoc = new XMLDocument2(); 

xmlDoc.parseXML(responseBody);
var num = xmlDoc.getNodeText('//RequesterID');

 

Not working. any suggestion??

 

 

 

Mohammed_Iqbal
Tera Guru

Hello Vineetha Rohra,

 I have store your response in one field and written business rule according to your requirement its working fine.

script:--

var res=current.getValue('u_response');
    
var xmlDoc = new XMLDocument2();

xmlDoc.parseXML(res);//you can user response body here.


 var num = xmlDoc.getNodeText('//sys_id');//here you write whta you want from response.


    gs.addInfoMessage(num);

 

find_real_file.png

 

HOPE THIS HELPFUL!!!!! MARK CORRECT OR HELPFUL.

Thanks,
Mohammed Iqbal