Thursday, November 15, 2018

Prevent the error, "Notice (SuiteScript) TypeError: Cannot find default value for object. ([SCRIPTNAME].js$sys#2162)" when creating a search through SuiteScript

When creating a search through SuiteScript, we usually follow this format:

var columns = new Array();
columns[0] = new nlobjSearchColumn('internalid');
columns[1] = new nlobjSearchColumn('phone');


var rec= nlapiSearchRecord('customer', null, null, columns);


Another way of creating a search through SuiteScript is using this format:

var columns = [new nlobjSearchColumn('internalid'), new nlobjSearchColumn('phone')];
       
var rec= nlapiSearchRecord('customer', null, null, columns);


The error "TypeError: Cannot find default value for object. ([SCRIPTNAME].js$sys#2162)" shows up when we forgot to add the keyword "new" for every instance of nlobjSearchColumn. Using the first format, it would be easy to detect if we forgot the "new" keyword even if we have a lot of nlobjSearchColumn entries because they are all aligned, therefore there is a less chance for us to get the error. But if we use the second format and we have defined many nlobjSearchColumn on the search, it would be difficult to catch if we forgot the "new" keyword on any one of them.

No comments:

Post a Comment