Hey <@UEZ4CRBST>, there isn't, but you can use a C...
# general
m
Hey @Michael Mascitto, there isn't, but you can use a COUNT formula field to do it or just keep calling getResults() and counting the length of the arrays returned
m
When I use getResults() to return a range of results and then try to iterate over them, i’m getting this error, “Java class “[L.nlobjSearchResult;” has no public instance field or method named ‘forEachResult’“. Any idea why?
i guess it return nlobjSearchResult instead of nlobjSearchResultSet after you use the getResults() method, and nlobjSearchResult doesn’t have the forEachResult() method. i guess they expect you to use a for loop to iterate through the page of results?
b
if you wanted to get up to 4000 search results, you can use forEachResult (https://system.na0.netsuite.com/app/help/helpcenter.nl?fid=section_N3124405.html#bridgehead_N3125880) instead of getResults
typically you get all your search results upfront as quickly as possible (to minimize the chances of new search results messing you up)
and then iterate through them
m
@Michael Mascitto It's as battk said. Generally, you need a double loop using searchResultSet.getResults() or you can use forEachResults, but you are limited to 4000.
Here's a simple example of the double loop (which is a good idea to use since the only real limit is your governance)
var filters = []; //stick filters here var columns = []; //stick columns here var search = nlapiCreateSearch('transaction', filters, columns); //you can change the type to something other than transaction //search starts here var results = search.runSearch().getResults(0,1000); //get the initial set of 0-1000 nlobjSearchResults (next_search_index 0) next_search_index = 1; //the next set we get will be 1000-2000 (next_search_index 1) //until we run out of SearchResultSets while(results != null && results.length > 0) { //iterate through the result set array for(var index = 0; index < results.length; index++) { var item = results[index]; //do your code with each item right here } //get the next SearchResultSet (and increment next_search_index) results = search.runSearch().getResults(next_search_index * 1000, next_search_index * 1000 + 999) next_search_index++; }
b
this is probably one of the uncommon times to actually use a do while loop
Copy code
//stick filters here
var filters = [];
//stick columns here
var columns = [];
//you can change the type to something other than transaction
var search = nlapiCreateSearch("transaction", filters, columns);
var resultSet = search.runSearch();

var setIndex = 0;
do {
  //get the next SearchResult array (and increment next_search_index)
  var results = resultSet.getResults(setIndex, (setIndex += 1000)) || [];

  //iterate through the results array
  //consider just concating the results into another array
  // to process after getting all search results
  for (var index = 0; index < results.length; index++) {
    //do your code with each result right here
    var result = results[index];
  }
} while (results.length);