XML Parsing issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
We are trying to connect ServiceNow and Workday with the SOAP API for Staffing, 'Put Assign Matrix Organization' and 'Put Remove Matrix Organization'. We have the request envelope and the action functional with the exception of the output of the response. See link below for the response xml.
I have the splitter set to /env:Envelope/env:Body/wd:Put_Remove_Matrix_Organization_Response and I've tried a few ways to get the node text and this is my latest code:
(function execute(inputs, outputs) {
try {
var xmlDoc = new XMLDocument2();
xmlDoc.setNamespaceAware(true);
xmlDoc.parseXML(inputs.sourceItem);
//gs.log(xmlDoc);
var matrix_event_reference = new Array();
// var count = 0;
// while (count < 999){
// count++;
var eventID = xmlDoc.getNodeText("/wd:Remove_from_Matrix_Organization_Event_Reference/wd:ID[@type='WID']");
if (eventID !== null){
var Matrix_Event_Reference_ID_List = {
ID: eventID
};
matrix_event_reference.push(Matrix_Event_Reference_ID_List);
// }
// }
outputs.targetObject = matrix_event_reference;
} catch (ex) {
gs.error('An exception occured while parsing - ' + inputs.sourceItem + ' \nPlease check the Exception - ' + ex);
outputs.state = 'SKIP';
return;
}
})(inputs, outputs);
I was attempting to iterate through the event references since it can be an array but I got no output so I changed it to try and get a single node text. Here is the outputs.
Any help would be appreciated as I am at wits end. This is the ~6th refactoring to get it fully functional.
Resources:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
I will suggest to convert XML to JSON and then parse and use that
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader