So I started out using nlapiSearchRecord, which has a 1000 limit per execution. I had the usual loop to check for the result set being of size 1000, to indicate there might be more records. This worked, but wasn't fast enough.
Then I found out about nlapiLoadSearch with a 4000 limit per execution. This seemed like my best bet, and would let me reduce my query executions by 3/4.
However, because of the types of reports my company needs, we often have a search with more than 4000 results. So I tried the same kind of a loop, so that after 4000 records, I would request another 4000. This doesn't seem to work with nlapiLoadSearch. I get this error:
ERROR: Code: UNEXPECTED_ERROR Super helpful, right? The error occurs right at the call to resultSet.forEachResult after the second time runSearch is called. Maybe nlapiLoadSearch is only able to be called once per script execution? Maybe something else is wrong with my code. Any help you could provide would be greatly appreciated.
var last_internalid = 0; var run = true; while(run){ var search = nlapiLoadSearch(null, 'my_saved_search_id'); //the saved search is ordered by internal id, and then line sequence number search.addFilter(new nlobjSearchFilter('internalidnumber', null, 'greaterthan', parseInt(last_internalid))); var resultSet = search.runSearch(); var count = 0; //call to resultSet.forEachResult second time through the while loop errors resultSet.forEachResult(function(result){ count++; last_internalid = result.getValue('internalid'); //application logic on results omitted //we can only call forEachResult 4000 times, so return false to indicate we don't wish to continue if(count >= 4000){ return false; } return true; }); if(resultSet == null || count < 4000){// no more results, end the search run = false; } }