"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

(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 (Error mentioned in Log)

})(request, response);

----------------------------------------------------------------------------------------------------------

Script include Code; (Error mentioned in Logs is highlighted in bold)

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();
},
getSerialNo: function(xmlString) {
var sn = '';
xmlString = xmlString.replace(/\s+/g, '');
var str = xmlString.split('<LineType>SN</LineType><LineText>');
var snstr = str[1].split('</LineText>');
sn = snstr[0];
this.logger.logDebug("KlickIT Delivery Advice Serial Number in function " + sn);
return sn;
},

put check

if(str.length>1){
var snstr = str[1].split('</LineText>');
sn = snstr[0];
this.logger.logDebug("KlickIT Delivery Advice Serial Number in function " + sn);
}

If this is solved, please close the thread.