XML Parsing issue

Kaileb
Tera Contributor

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.

Kaileb_0-1765899301085.png

 

 

Any help would be appreciated as I am at wits end. This is the ~6th refactoring to get it fully functional.

 

Resources:

https://community.workday.com/sites/default/files/file-hosting/productionapi/Staffing/v45.1/samples/...

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Kaileb 

I will suggest to convert XML to JSON and then parse and use that

AnkurBawiskar_0-1765900193042.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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