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

Chuck Tomasi
Tera Patron

This sounds like a classic case a web service import set.



SOAP web service import sets


I am not getting it... my concern is this I want all the contents like name, manager etc fetch from the XML based on the associate user id and then map it to my custom table where we have all these fields and make sure that the value from the web service gets update in that table on weekly basics automatically. I am guessing we might have to create a schedule job but how we perform all this task under one schedule job.


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Shubham,



Here is the script. I ran in background script and is able to get all the values in an array. this script ran in global scope.



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);



If you want to take all the following values such as AssociateUser, Department, Projects, PrimaryLocation, LegalEntity, Location, CostBand , BU, LOB, CLOB



then declare array for those and repeat the lines within for loop and push the values in individual array.



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

Thanks for the reply. how i can automate this process that this value get mapped to my custom table where i have all these fields and then it should updated on weekly basics based on my webservice response.?


Hi Shubham,



Are you saying that:


1) you have a web service which you will consume daily and you will get response something similar to the one you have posted


2) parse the xml response and update the records of some table based on value present in the xml.



Option 1:


1) Create web service in your system


2) create fields for this web service based on the 11 values you are getting in the xml


3) have transform map


4) have field map and have coalesce field.


5) create soap message and consume your web service and send the 11 values and transform map, field map will take care of updating the values



Option 2:


1) you are getting the xml in response daily from third party after you have consumed the endpoint


2) query the target table on something unique may be employee name etc. you need to decide on this


3) update the table record if found based on values present in the xml after parsing the response.



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