Resolve Netsuite Scripting Error "Cannot read property "length" from null"

One of the common errors while searching a record using script is  "Cannot read property length from null". This error occurs when you try to get length of search record object which returns a null value.
Length method can be used only if search record API returns some value. If it returns null, then length method should not be used.

For eg. below code will return a error if search record gives no result-

var results = nlapiSearchRecord('salesorder', null, filters, columns); 

nlapiLogExecution('DEBUG', 'search results', results.length);


To remove this error add a condition to check if result is null or not

var results = nlapiSearchRecord('salesorder', null, filters, columns);

if(results!=null)

{

      nlapiLogExecution('DEBUG', 'search results', results.length);
}
contact us at:
Email : info@smilingcoders.com

Comments

Popular posts from this blog

USING CASE (IF AND ELSE) IN NETSUITE SAVED SEARCH- NETSUITE ACADEMY

Calling User Event Script from another User Event

HOW TO SET SUBLIST SUB RECORD VALUES IN SUITE SCRIPT 1.0 AND 2.0