Work Around the 1000 Row Limit Returned by Saved Searches in Netsuite

Work Around the 1000 Row Limit Returned by Saved Searches in Netsuite

nlapiSearchRecord can return only upto 1000 rows. But there is a work around to retrieve more than 1000 rows. This can be done by first sorting the result based on internal id and then using while loop and use concat method to get all results by internalid number as a filter inside the while loop. The sample code is given below:

var filters = new Array();

filters[1] = new nlobjSearchFilter(‘mainline’,null,’is’,’T’);

var columns = new Array();


columns[0] = new nlobjSearchColumn(‘internalid’).setSort(); //sort the result based on internalid


var results = nlapiSearchRecord(‘transaction’,null,filters,columns); //search record

var completeResultSet = results; //copy the result

while(results.length == 1000){ //if there are more than 1000 records

     var lastId = results[999].getValue(‘internalid’); //note the last record retrieved
     filters[2] = new nlobjSearchFilter(‘internalidnumber’,null,’greaterthan’,lastId); //create new filter to restrict the next search based on the last record returned
     results = nlapiSearchRecord(‘transaction’,null,filters,columns);

     completeResultSet = completeResultSet.concat(results); //add the result to the complete result set 
}
 

Log out of this account

Leave a Reply