Parse the XML content received from webservice SOAP response

shubham5957
Mega Contributor

I want to retrieve the content(like name, manager, project etc...) of the webservice response received through SOAP API and map to a custom table that will get updated on weekly basics.

18 REPLIES 18

Dave Smith1
ServiceNow Employee
ServiceNow Employee

I could probably do it using XSLT.. where do you want this information to end up?



Will you want the platform to fetch the XML then inject content into a table, or have the target push the right content into the table?   The latter could use the REST API.


I want all the contents like name, manager etc fetch from the xml based on the userid and then map it to my custom table where we have all these fields and make sure that the value from the webservice gets update in that table on weekly basics automatically.


So are you looking at:


  • a scheduled job from your data source that pushes it to your instance (using REST API)
  • or a scheduled job on your instance that fetches it from a data source and populates your tables (like a scheduled import set)...?

yes a schedule job that will first fetch the data of employee based on the associate user id and then map it to my custom table. i got the data fetch from the XML but for that I have to convert it into CSV and then use the script to get the data from XML. How i can automate the whole process? This is the script i used to fetch the data from XML response which i am getting from webservice response.




var xmlString = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><PullDataResponse xmlns="http://tempuri.org/"><PullDataResult><EmplyeeData><RecordCount>2</RecordCount><Employee><AssociateUser>abdul.gani</AssociateUser><EmplyeeName>ABDUL GANI Garu</EmplyeeName><Manager>MOHAMMED ALI</Manager><Department>GNOC</Department><Projects>,IN1_17_90201403,,,,,,,US1_18_0121_01,</Projects><PrimaryLocation></PrimaryLocation><WorkerType>Employee</WorkerType><LegalEntity>IN1</LegalEntity><Location>BAN</Location><CostBand>CBSES_IN1</CostBand><BU>SHRS_DEL</BU><LOB>MAINT</LOB><CLOB></CLOB></Employee><Employee><AssociateUser>abhijeet.jadhav</AssociateUser><EmplyeeName>ABHIJEET B JADHAV garu</EmplyeeName><Manager>SANAL MANSHIVA</Manager><Department>SUP</Department><Projects>IN1_16_0108_01,IN1_17_90403403</Projects><PrimaryLocation></PrimaryLocation><WorkerType>Employee</WorkerType><LegalEntity>IN1</LegalEntity><Location>PUN</Location><CostBand>CBSES_IN1</CostBand><BU>IND</BU><LOB>MAINT</LOB><CLOB></CLOB></Employee></EmplyeeData></PullDataResult></PullDataResponse></s:Body></s:Envelope>';




var xmldoc = new XMLDocument(xmlString);


var noParamNode = xmldoc.getNodes("//Employee").getLength();


var EmplyeeNameArray = [];


var ManagerArray = [];


for(var k=1; k<noParamNode+1; k++){


var EmplyeeName = xmldoc.getNodeText("//Employee["+k+"]/EmplyeeName");


var Manager = xmldoc.getNodeText("//Employee["+k+"]/Manager");


EmplyeeNameArray.push(EmplyeeName.toString());


ManagerArray.push(Manager.toString());


}



gs.print('EmplyeeNameArray array is::'+EmplyeeNameArray);


gs.print('ManagerArray array is::'+ManagerArray);