- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 03:28 AM
Hi All,
I need to fetch a value from the response body which i have received it from the SOAP step:
Fig:
Can some help me how do i fetch any value from the xml response which i am getting in the responsebody input variable?
Thanks,
Ak
Solved! Go to Solution.
- Labels:
-
flow designer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 11:34 AM
So the problem is the body which is returned from integration.
See formatted XML
Below works but it's not good for long time solution.
var response = inputs.response_body.toString();
var xmldoc = new XMLDocument(response);
if(xmldoc.toString().indexOf('name=') > -1){
var nm1 = (xmldoc.toString().split('name="')[1]);
var nm2 = (nm1.toString().split('"')[0]);
outputs.groupname = nm2;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 08:30 PM
Hi,
the xml doesn't have proper starting and closing tags i.e. < and >
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 08:50 PM
Hi,
If the response is proper as below; you should be able to get the value as below
Please update code as below
(function execute(inputs, outputs) {
// ... code ...
var responseBody = inputs.response_body;
var xmldoc = new XMLDocument(responseBody);
var name = xmldoc.getAttribute("//row", "name");
var email = xmldoc.getAttribute("//row", "email");
outputs.groupname = name;
})(inputs, outputs);
Sample script which I ran in background script
var xml = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetSupportSpecialistByLocationResponse xmlns="http://nda.sys.com/"><GetSupportSpecialistByLocationResult><nda-response id="getassociations" status="OK"><association><people></people><groups><row name="India - Banaglore" email="indbgl@xyz.com" /></groups></association></nda-response></GetSupportSpecialistByLocationResult></GetSupportSpecialistByLocationResponse></soap:Body></soap:Envelope>';
var xmldoc = new XMLDocument(xml);
var name = xmldoc.getAttribute("//row", "name");
var email = xmldoc.getAttribute("//row", "email");
gs.info(name);
gs.info(email);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 08:53 PM
Hi
I am getting the below response from the soap.
I copy pasted the rendered HTML in background script and execute it with the below script, where i got the output.
var response = inputs.response_body;
var xmldoc = new XMLDocument(response);
var name = xmldoc.getNodeText("//row/@name")
gs.print(name);
below are the same response which i got from soap step.
so i question is how can i pass Rendered HTML thing to script step so that i can fetch any node.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 09:12 PM
on passing the soap response to xml parser i am getting the response as below:
{
"Envelope": {
"Body": {
"name$": "Body",
"GetSupportSpecialistByLocationResponse": {
"name$": "GetSupportSpecialistByLocationResponse",
"GetSupportSpecialistByLocationResult": "<nda-response id=\"getassociations\" status=\"OK\"><association from_entity_guid=\"123456789\" business_process_role_guid=\"123456789\"><people></people><groups><row group_guid=\"123456789\" name=\"IND - BGL\" email=\"indbgl@xyz.com\" ordinal=\"0\" description=\"\" association_guid=\"123456789\"/></groups></association></nda-response>"
}
}
}
}
if i pass this response to Script step, can i fetch those values?
regards,
Ak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 10:03 PM
Hi,
so now you are converting xml to json?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader