RE: UNEXPECTED_ERROR (TypeError: null is not a function, it is object. (NLRecordScripting.scriptInit$sys#495(eval)#1) )

Hi,

I am creating the timesheet through the scripting but it is not created.

I am getting the UNEXPECTED_ERROR (TypeError: null is not a function, it is object. (NLRecordScripting.scriptInit$sys#495(eval)#1) ).

This is the script for creating the timesheet.

var recObj=nlapiCreateRecord(‘timesheet’,{recordmode:’dynamic’});
nlapiLogExecution(‘Debug’,’recObj’,recObj);
var date=nlapiStringToDate(’10/20/2019′);
nlapiLogExecution(‘Debug’,’date’,date);
recObj.setFieldValue(‘trandate’,date);
recObj.setLineItemValue(‘timeitem’,’customer’,1,956);
recObj.setLineItemValue(‘timeitem’,’casetaskevent’,1,51);
recObj.setLineItemValue(‘timeitem’,’item’,1,13);
recObj.setLineItemValue(‘timeitem’,’hours4′,1,’2:00′);
recObj.setLineItemValue(‘timeitem’,’hourstotal’,1,’2:00′);
var recId=nlapiSubmitRecord(recObj,true,true);
nlapiLogExecution(‘Debug’,’recId’,recId);
var recObj1=nlapiLoadRecord(‘timesheet’,recId);
var trandate= recObj1.getFieldValue(‘trandate’);
nlapiLogExecution(‘Debug’,’trandate’,trandate);

 

RE: UNEXPECTED_ERROR (TypeError: null is not a function, it is object. (NLRecordScripting.scriptInit$sys#495(eval)#1) )

 

Can you please help me anyone on this issue.

samallasravan564 Rookie Asked on October 28, 2019 in SuiteScript.

This error occurs when you read a property or call a method on a null object . That’s because the DOM API returns null for object references that are blank. An object is expected somewhere and wasn’t provided. So, you will get null is not an object error if the DOM elements have not been created before loading the script. In JavaScript , null is not an object; and won’t work. You must provide a proper object in the given situation.

We can resolve this type of issues by adding an event listener that will notify us when the page is ready. Once the addEventListener is fired, the init() method can make use of the DOM elements.


document.addEventListener('readystatechange', function() {

if (document.readyState === "complete") {

init();

}

 

on April 16, 2020.
Add Comment
2 Answers

dmashburn3 is right here. You need to first select the line, set vales, commit lines subrecord, commit line object and then finally submit timesheet object. Please see the API calls below for reference. You may find more details in the NetSuite help under ‘Timesheets Guide’- /app/help/helpcenter.nl?fid=section_3891941390.html

var obj = nlapiCreateRecord(‘timesheet’, {“recordmode”:”dynamic”});

obj.selectNewLineItem(‘timegrid’);

var sublistSubrecord = obj.createCurrentLineItemSubrecord(‘timegrid’, ‘sunday’);

sublistSubrecord.setFieldValue(‘customer’, ’48’);

sublistSubrecord.setFieldValue(‘item’, ‘117’);

sublistSubrecord.setFieldValue(‘location’, ‘1’);

sublistSubrecord.setFieldValue(‘hours’, ‘8:00’);

sublistSubrecord.setFieldValue(‘memo’, ‘timeentry created’);

sublistSubrecord.setFieldValue(‘isbillable’, ‘T’);

sublistSubrecord.setFieldValue(‘payrollitem’, ‘2’);

sublistSubrecord.setFieldValue(‘paidexternally’, ‘T’);

sublistSubrecord.setFieldValue(‘price’, ‘1’);

sublistSubrecord.setFieldValue(‘overriderate’, ‘T’);

sublistSubrecord.setFieldValue(‘department’, ‘1’);

sublistSubrecord.setFieldValue(‘class’, ‘1’);

sublistSubrecord.commit();

obj.commitLineItem(‘timegrid’);

var id = nlapiSubmitRecord(obj);

Beginner Answered on October 29, 2019.

Thank you for your response.

on October 30, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.