All of a sudden, our users complained that one of our NetSuite process failed. They reported this error:
TypeError: Cannot call method “getTime” of null (some_code.js$sys#791)
I tried to debug the code using nlapiLogExecution can still couldn’t locate where the error occured. I up the ante by using the script debugger and found that the error happens because the code is trying to call the getTime of a null object. Pretty self explanatory, but why did it happen? The code roughly looks like this:
var billDate = nlapiStringToDate(billDateStr);
var billTime = billDate.getTime();
This used to work fine. Notice that I didn’t test my billDateStr if it’s empty because I know that nlapiStringToDate will return the current date in case the date string that I passed is null or empty. NetSuite’s 2009.2 release handles this differently. Searching for answers in their help page, I found this article inside their release note:
Starting with 2009.2, passing an empty string to the nlapiStringToDate(str) function returns null. Prior to this release, passing an empty string returned the current date. For example, in this snippet, the value of emptydate used to be the current date; now it is null.
var emptydate = nlapiStringToDate(”);
nlapiLogExecution(‘DEBUG’, ‘emptydate’, emptydate);
I wonder why they changed the implementation of nlapiStringToDate. Nevertheless, now I learned my lesson. Reading the release notes has its benefits.
0 Responses to “New Implementation of nlapiStringToDate in 2009.2”
Leave a Reply