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);
Can you please help me anyone on this issue.
For one, it looks like you’re making your timesheet record in dynamic mode. If you’re going to do dynamic, you’ll need to select the line, set the values, and commit the line.
Thank you for your response.
jefryarch
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.