Hey Guys, I am getting this "TypeError: Cannot rea...
# suitescript
a
Hey Guys, I am getting this "TypeError: Cannot read property "0" from null" error while creating the custom record in NetSuite? How can I resolve this issue?
m
You probably need to share code.
a
Hi @michoel, here is the code function createRubrikBAIFileRecords(baiRecord,baiCustomerName,baiAmount,baiDate,fileName,accountInternalId,baiDescription,baiMappingInternalId,transRecId,transImpact,recordType,fileImport) { var rubrikBAIFileId = null; var convertedDate = null; try { if(isNotNull(baiDate)) { var nsDate = baiDate.substring(2,4) + "/" + baiDate.substring(4,6) + "/" + "20" + baiDate.substring(0,2); convertedDate = convertIntoDate(nsDate); } if(isNotNull(accountInternalId)) { var rubrikBAIFile = record.create({ type: 'customrecord_rubrik_bai_file_records' }); if(isNotNull(baiCustomerName)) { rubrikBAIFile.setValue({ fieldId: 'custrecord_upy_customer_name', value: baiCustomerName }); } if(transImpact == 1) { if(isNotNull(baiAmount)) { rubrikBAIFile.setValue({ fieldId: 'custrecord_upy_amount', value: ((baiAmount/100).toFixed(2)) }); } } else { if(isNotNull(baiAmount)) { rubrikBAIFile.setValue({ fieldId: 'custrecord_upy_amount', value: '-' + ((baiAmount/100).toFixed(2)) }); } } if(isNotNull(convertedDate[0])) { rubrikBAIFile.setValue({ fieldId: 'custrecord_upy_date', value: convertedDate[0] }); } if(isNotNull(fileName)) { rubrikBAIFile.setValue({ fieldId: 'custrecord_upy_bai_statement_name', value: fileName }); } if(isNotNull(accountInternalId)) { rubrikBAIFile.setValue({ fieldId: 'custrecord_upy_from_account', value: accountInternalId }); } if(isNotNull(baiDescription)) { rubrikBAIFile.setValue({ fieldId: 'custrecord_upy_description', value: baiDescription }); } if(isNotNull(baiMappingInternalId)) { rubrikBAIFile.setValue({ fieldId: 'custrecord_upy_bai_mapping_record', value: baiMappingInternalId }); } if(isNotNull(transRecId)) { rubrikBAIFile.setValue({ fieldId: 'custrecord_upy_netsuite_record', value: transRecId }); } if(isNotNull(fileImport)) { rubrikBAIFile.setValue({ fieldId: 'custrecord_upy_bai_file_import', value: fileImport }); } if(isNotNull(recordType)) { rubrikBAIFile.setValue({ fieldId: 'custrecord_upy_record_type_bai__file', value: recordType }); } rubrikBAIFileId = rubrikBAIFile.save(); log.debug('RUBRIK','Rubrik BAI File Records created: Internal Id:: ' + rubrikBAIFileId); } else { log.debug('RUBRIK','Account is not available in NetSuite: BAI Account'); } } catch(e) { log.error('ERROR','Exception while creating Rubrik BAI File Record: ' + e.toString()); } return rubrikBAIFileId; } function convertIntoDate(nsDate) { try { var parsedDateStringAsRawDateObject = format.parse({ value: nsDate, type: format.Type.DATE }); var formattedDateString = format.format({ value: parsedDateStringAsRawDateObject, type: format.Type.DATE }); return [parsedDateStringAsRawDateObject, formattedDateString]; } catch(e) { log.error('RUBRIK','Exception in converting date: ' + e.toString()); } }
n
Not sure but could be that convertedDate, from the line:
Copy code
if (isNotNull(convertedDate[0])) {
is null?
☝️ 1
a
Code.js
m
Stack trace should tell you exactly which line
a
Thanks @Nikola Gavric and @michoel, now issue resolved.
👍 1
The issue was in convertDate[0].