"Cannot read property "0" from undefined:" Error Message

devendranarun
Tera Guru

Hello @Ankur Bawiskar 

In Servicenow logs, we are getting this below Error;

Cannot read property "0" from undefined: com.glide.rest.domain.ServiceException: Cannot read property "0" from undefined: com.glide.rest.service.custom.CustomServiceExceptionResolver.throwServiceException(CustomServiceExceptionResolver.java:82)
com.glide.rest.service.custom.CustomServiceExceptionResolver.throwServiceException(CustomServiceExceptionResolver.java:77)
com.glide.rest.service.custom.CustomServiceExceptionResolver.resolveForException(CustomServiceExceptionResolver.java:45)
com.glide.rest.service.custom.CustomServiceResultHandler.handle(CustomServiceResultHandler.java:22)
com.glide.rest.service.custom.CustomService.execute(CustomService.java:85)
com.glide.rest.handler.impl.ServiceHandlerImpl.invokeService(ServiceHandlerImpl.java:37)
com.glide.rest.processors.RESTAPIProcessor.process(RESTAPIProcessor.java:344)
com.glide.processors.AProcessor.runProcessor(AProcessor.java:596)
com.glide.processors.AProcessor.processTransaction(AProcessor.java:266)
com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:181)
com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:169)
com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:44)
com.glide.sys.Transaction.run(Transaction.java:2338)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)

This is an Integration and the Client says that they are getting the below Error;

Error: 500 Internal Server Error
{
"error": {
"message": "Cannot read property \"0\" from undefined",
"detail": "TypeError: Cannot read property \"0\" from undefined (sys_ws_operation.83e74315db2673808f145487dc961905.operation_script; line 9)"
},
"status": "failure"
}

But, this has not affected the flow of Integration and its working fine.

Found this below code snippet (Script include) which has the Property in it;

var partnerId;
var specialLocationCity = gs.getProperty('com.klickit.order.spl.location.city');
var pcLifeLocationCity = current.variables.pc_life_location.city;
if (specialLocationCity.contains(pcLifeLocationCity)) {
partnerId = JSON.parse(specialLocationCity)[pcLifeLocationCity];
} else {
partnerId = current.variables.pc_life_company.u_code;
}

The value of the Property is;

{
"Chennai": "266755"
}

Type of this property is String.

Your help is highy appreciated.

Best Regards,
Arun Devendran

 

 

7 REPLIES 7

Upender Kumar
Mega Sage

check if 

if(specialLocationCity !=''){
your code

}

Prashant Dubey
ServiceNow Employee
ServiceNow Employee

Hi Arun,

Try the below code 

var specialLocationCityJSON = specialLocationCity ? JSON.parse(specialLocationCity):{};
if (specialLocationCityJSON.hasOwnProperty(pcLifeLocationCity)) {
partnerId = specialLocationCityJSON[pcLifeLocationCity];
}

Pranesh072
Mega Sage
Mega Sage

Can you share the whole script?

 

"detail": "TypeError: Cannot read property \"0\" from undefined (sys_ws_operation.83e74315db2673808f145487dc961905.operation_script; line 9)"

Hi Pranesh,

I checked this line

(sys_ws_operation.83e74315db2673808f145487dc961905.operation_script; line 9)

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

// implement resource here
var requestBody = request.body;
var requestString = requestBody.dataString;
gs.log('setDeliveryAdvice '+requestString);

var procDelAdv = new WartKlickITOrderProcess();
procDelAdv.processDeliveryAdvice(requestString); //line 9

})(request, response);

 

Script include code;

processDeliveryAdvice: function(requestString) {

var xmldoc = new XMLDocument(requestString);
var freightNote = xmldoc.getNodeText("//FreightNote");
var trackingLink = xmldoc.getNodeText("//TrackingLink");
var RITMno = xmldoc.getNodeText("//TransactionID");
var pDelDate = xmldoc.getNodeText("//DeliveryDate");
var tabName = '';

gs.log("XXX Flags from include :" + freightNote + " : " + trackingLink + " : " + RITMno + " : " + pDelDate);

if (freightNote == '' || trackingLink == '' || RITMno == '' || pDelDate == '') {

 

errmsg = 'Mandatory details missing';
this.logger.logErr('KlickIT Delivery Advice Interrupted ' + errmsg);
}
this.logger.logDebug("KlickIT Delivery Advice Transaction ID " + RITMno);
var ritm = this.getRITMObj(RITMno);
//ritm.variables.pc_delivery_information = "Tracking Number : "+freightNote+"\nTrackingLink : "+trackingLink;

ritm.variables.pc_tracking_number = freightNote;
ritm.variables.pc_tracking_link = trackingLink;
ritm.variables.pc_delivery_date = pDelDate;
var SN = this.getSerialNo(requestString);
this.logger.logDebug("KlickIT Delivery Advice Tracking number " + freightNote);
this.logger.logDebug("KlickIT Delivery Advice Tracking link " + trackingLink);
this.logger.logDebug("KlickIT Delivery Advice Delivery date " + pDelDate);
this.logger.logDebug("KlickIT Delivery Advice Serial Number " + SN);

if ((ritm.variables.vs_is_ot_system) && ritm.variables.vs_is_ot_system == 'true')
tabName = 'u_cmdb_ci_ot_other_device';
else
tabName = 'u_cmdb_ci_end_user_device';

var gr = new GlideRecord(tabName);
gr.get(ritm.variables.pc_life_created_device);
gr.serial_number = SN;
ritm.variables.os_pc_ser_no = SN;
ritm.variables.pc_life_serial_number = SN;
gr.update();
ritm.update();
},