How to parse soap response body

Anil kumar Sha2
Mega Expert

Hello Team,

i have received the record using soap getMethod but i am not able to get the value of description and short description  to create the incident in servicenow.

i tried from below method  but value is not coming of description and short description. Plsl help

Var obj=new XMLHelper().toObject(responseBody); 

gs.log('objeInfo=' +obj);
assetDescription=obj["SOAP-ENV:Body"].getRecordsResponse.getRecordsResult.description;
gs.log("assetDescription=" +assetDescription)

 

 

 

scriptinclude=:<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body><getRecordsResponse><getRecordsResult><active>0</active><activity_due></activity_due><additional_assignee_list/><approval>not requested</approval><approval_set></approval_set><assigned_to>9ee1b13dc6112271007f9d0efdb69cd0</assigned_to><assignment_group>287ee6fea9fe198100ada7950d0b1b73</assignment_group><business_duration>1970-01-22 14:03:10</business_duration><business_service/><business_stc>1864990</business_stc><calendar_duration>1970-04-01 21:03:10</calendar_duration><calendar_stc>7851790</calendar_stc><caller_id>5137153cc611227c000bbd1bd8cd2005</caller_id><category>database</category><caused_by/><child_incidents>0</child_incidents><close_code>Closed/Resolved by Caller</close_code><close_notes>Closed before close notes were made mandatory
</close_notes><closed_at>2020-02-18 22:54:55</closed_at><closed_by>9ee1b13dc6112271007f9d0efdb69cd0</closed_by><cmdb_ci/><comments_and_work_notes></comments_and_work_notes><company>31bea3d53790200044e0bfc8bcbe5dec</company><contact_type>phone</contact_type><contract/><correlation_display/><correlation_id/><delivery_plan/><delivery_task/><description>Currently running 10GR1 and need to upgrade to 10GR2.</description><due_date></due_date><escalation>0</escalation><expected_start></expected_start><follow_up></follow_up><group_list/><hold_reason>0</hold_reason><impact>2</impact><incident_state>7</incident_state><knowledge>0</knowledge><location>108752c8c611227501d4ab0e392ba97f</location><made_sla>0</made_sla><notify>1</notify><number>INC0000010</number><opened_at>2020-02-13 22:53:02</opened_at><opened_by>9ee1b13dc6112271007f9d0efdb69cd0</opened_by><order>0</order><parent/><parent_incident/><priority>4</priority><problem_id/><reassignment_count>2</reassignment_count><reopen_count>0</reopen_count><reopened_by/><reopened_time></reopened_time><resolved_at>2020-05-14 19:56:12</resolved_at><resolved_by>6816f79cc0a8016401c5a33be04be441</resolved_by><rfc/><service_offering/><severity>3</severity><short_description>Geeta rani From Bareilly </short_description><skills/><sla_due></sla_due><sn_esign_document/><sn_esign_esignature_configuration/><sn_hr_le_activity/><state>7</state><subcategory/><sys_class_name>incident</sys_class_name><sys_created_by>don.goodliffe</sys_created_by><sys_created_on>2020-02-25 22:54:41</sys_created_on><sys_domain>global</sys_domain><sys_domain_path>/</sys_domain_path><sys_id>46b9490da9fe1981003c938dab89bda3</sys_id><sys_mod_count>10</sys_mod_count><sys_updated_by>incidentAlert</sys_updated_by><sys_updated_on>2020-09-27 06:40:49</sys_updated_on><time_worked></time_worked><u_incident_alert/><u_sap_number/><u_ts_danc/><upon_approval/><upon_reject/><urgency>3</urgency><user_input></user_input><watch_list/><work_end></work_end><work_notes_list/><work_start></work_start></getRecordsResult><getRecordsResult><active>1</active><activity_due></activity_due><additional_assignee_list/><approval>not requested</approval><approval_set></approval_set><assigned_to/><assignment_group/><business_duration></business_duration><business_service/><business_stc>0</business_stc><calendar_duration></calendar_duration><calendar_stc>0</calendar_stc><caller_id>cc6bba63079310104d05f16c7c1ed0e9</caller_id><category>database</category><caused_by/><child_incidents>0</child_incidents><close_code/><close_notes/><closed_at></closed_at><closed_by/><cmdb_ci/><comments_and_work_notes></comments_and_work_notes><company/><contact_type/><contract/><correlation_display/><correlation_id/><delivery_plan/><delivery_task/><description>Testing999999999</description><due_date></due_date><escalation>0</escalation><expected_start></expected_start><follow_up></follow_up><group_list/><hold_reason>0</hold_reason><impact>3</impact><incident_state>1</incident_state><knowledge>0</knowledge><location/><made_sla>1</made_sla><notify>1</notify><number>INC0010722</number><opened_at>2020-09-23 08:35:37</opened_at><opened_by>cc6bba63079310104d05f16c7c1ed0e9</opened_by><order>0</order><parent/><parent_incident/><priority>5</priority><problem_id/><reassignment_count>0</reassignment_count><reopen_count>0</reopen_count><reopened_by/><reopened_time></reopened_time><resolved_at></resolved_at><resolved_by/><rfc/><service_offering/><severity>3</severity><short_description>Geeta rani From Bareilly </short_description><skills/><sla_due></sla_due><sn_esign_document/><sn_esign_esignature_configuration/><sn_hr_le_activity/><state>1</state><subcategory>db2</subcategory><sys_class_name>incident</sys_class_name><sys_created_by>incidentAlert</sys_created_by><sys_created_on>2020-09-23 08:35:37</sys_created_on><sys_domain>global</sys_domain><sys_domain_path>/</sys_domain_path><sys_id>eabe4faf079310104d05f16c7c1ed0cd</sys_id><sys_mod_count>2</sys_mod_count><sys_updated_by>incidentAlert</sys_updated_by><sys_updated_on>2020-09-27 06:41:39</sys_updated_on><time_worked></time_worked><u_incident_alert/><u_sap_number/><u_ts_danc/><upon_approval>proceed</upon_approval><upon_reject>cancel</upon_reject><urgency>3</urgency><user_input></user_input><watch_list/><work_end></work_end><work_notes_list/><work_start></work_start></getRecordsResult><getRecordsResult><active>1</active><activity_due></activity_due><additional_assignee_list/><approval>not requested</approval><approval_set></approval_set><assigned_to/><assignment_group>5f63e48fc0a8010e00eeaad81cd4dd37</assignment_group><business_duration></business_duration><business_service/><business_stc>0</business_stc><calendar_duration></calendar_duration><calendar_stc>0</calendar_stc><caller_id>cc6bba63079310104d05f16c7c1ed0e9</caller_id><category>database</category><caused_by/><child_incidents>0</child_incidents><close_code/><close_notes/><closed_at></closed_at><closed_by/><cmdb_ci/><comments_and_work_notes></comments_and_work_notes><company/><contact_type/><contract/><correlation_display/><correlation_id/><delivery_plan/><delivery_task/><description>HanuMaansdsasdasd22222</description><due_date></due_date><escalation>0</escalation><expected_start></expected_start><follow_up></follow_up><group_list/><hold_reason>0</hold_reason><impact>3</impact><incident_state>2</incident_state><knowledge>0</knowledge><location/><made_sla>1</made_sla><notify>1</notify><number>INC0010755</number><opened_at>2020-09-24 11:29:51</opened_at><opened_by>cc6bba63079310104d05f16c7c1ed0e9</opened_by><order>0</order><parent/><parent_incident/><priority>5</priority><problem_id/><reassignment_count>3</reassignment_count><reopen_count>0</reopen_count><reopened_by/><reopened_time></reopened_time><resolved_at></resolved_at><resolved_by/><rfc/><service_offering/><severity>3</severity><short_description>Geeta rani From Bareilly </short_description><skills/><sla_due></sla_due><sn_esign_document/><sn_esign_esignature_configuration/><sn_hr_le_activity/><state>2</state><subcategory>sql server</subcategory><sys_class_name>incident</sys_class_name><sys_created_by>incidentAlert</sys_created_by><sys_created_on>2020-09-24 11:29:51</sys_created_on><sys_domain>global</sys_domain><sys_domain_path>/</sys_domain_path><sys_id>3030c948076350104d05f16c7c1ed07d</sys_id><sys_mod_count>22</sys_mod_count><sys_updated_by>incidentAlert</sys_updated_by><sys_updated_on>2020-09-27 06:41:00</sys_updated_on><time_worked></time_worked><u_incident_alert>142009042fa3501030e8532a2799b655</u_incident_alert><u_sap_number/><u_ts_danc/><upon_approval>proceed</upon_approval><upon_reject>cancel</upon_reject><urgency>3</urgency><user_input></user_input><watch_list/><work_end></work_end><work_notes_list/><work_start></work_start></getRecordsResult></getRecordsResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

1 ACCEPTED SOLUTION
14 REPLIES 14

Good Morning Sir

Lot of thanks to give the Support.

last question : response will automatically send back to third party  or do i need to write any code to send the response  ? Pls Suggest

Response from what?

Isn't the script pulling the data from the third party app? In this case, isn't the soap message a response?

If there's a need to send a message that a incident has been created, that'll require a new script to send an outbound message.

Hi Sir,

i am consuming the soap web services using get Record method through schedule job. when this web services get the record from other ServiceNow instance (https://dev100084.service-now.com/incident.do?wsd)and create  the incident  on instance (https://dev78350.service-now.com/)   then response should be back to  instance (https://dev100084.service-now.com/incident.do?wsdl)?  if we will not send the response then they will not able to capture the incident number and sys_id to update the incident in instance (https://dev78350.service-now.com/)?

how we can send the response ? Pls guide me 

try {
var s = new sn_ws.SOAPMessageV2('Get Incidents from Incident Table', 'getRecords');
//s.setStringParameterNoEscape('__encoded_query','category=database');
s.setStringParameterNoEscape('getRecords.__encoded_query', 'category=database');
var response = s.execute();
var responseBody = response.getBody();
gs.log("scriptinclude1=:" +responseBody);
var status = response.getStatusCode();

var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(responseBody);

var recordsResult = xmlDoc.getFirstNode("//getRecordsResult");
while (recordsResult) {
if (recordsResult) {
var description = '';
var short_description = '';
var iter = recordsResult.getChildNodeIterator();
while (iter.hasNext()) {
var n = iter.next();
switch (n.getNodeName()) {
case 'description':
description = n.getTextContent();
break;
case 'short_description':
short_description = n.getTextContent();
break;
}
}

var grinc = new GlideRecord('incident');
grinc.gr.initialize();
grinc.description = description;
grinc.short_description = short_description;
grinc.insert();
}
recordsResult = xmlDoc.getNextNode(recordsResult);
}


}

catch(ex) {
var message = ex.message;
}

Is is possible to create a new question on sending the reply back? The original question was just about getting value out from the SOAP xml file. We're digressing from the question from the topic.

Okey Sir