Cannot read property "0" from undefined incident integration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 04:47 PM
Hi guys!
I'm learning SOAP integration between 2 instances because in a few days I'll make it in a project between Servicenow and Service Manager.
For now I'm integrating between 2 instances, making a BR/UI Action that calls a Script Include where the magic happens.
When I'm running the Script Include, and reviewing losgs I'm not able to replicate incident in the other instance because I'm getting some errors.
Jus as a reminder the information needs to travel in XML format.
This is part of my code:
var incident_object = this.createIncidentObject(incident_sysid);
//invocamos al soap de insert
try {
var s = new sn_ws.SOAPMessageV2('incidentIntegrationSN', 'insert');
var response = s.execute();
var responseBody = response.getBody();
var status = response.getStatusCode();
gs.info('Status: ' + status);
gs.info("Incident replica response: " + responseBody.toString());
//if http is successful
if (status == 200 || status == 201) {
var obj = responseBody.getBody();
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(responseBody);
gs.info("Objeto 1: " + xmlDoc);
var sm_incident_status = xmlDoc.getNodeText("//number");
var sm_incident_status_message = obj.result[0].status_message;
var sm_incident_display_value = obj.result[0].display_value;
var sm_incident_sys_id = obj.result[0].sys_id;
var sm_incident_record_link = obj.result[0].record_link;
var inc_number = incident.getValue('number');
gs.info("Objeto 2: " + inc_number);
gs.info("Objeto 3: " + sm_incident_status);
And this is the log, what I'm getting:
Hope you guys could help me, please.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 09:58 PM
Hi, the only place your code appears to show a reference to 0, is when you read element 0 from array 'result'.
Can you debug\log obj.result to confirm its format\data type, as it may be that 'result' is not any array and so result[0] is not valid.