how to fix No more than 4000 search results may be...
# ask-stanley-ai
n
how to fix No more than 4000 search results may be returned at one time from nlobjSearchResultSet.forEachResult in suitelet suitescript
c
AI generated answer (using internal Slack threads):
The error you're encountering, "No more than 4000 search results may be returned at one time", is due to the limitation of the
nlobjSearchResultSet.forEachResult
method in SuiteScript. This method can only handle up to 4000 results at a time. To overcome this limitation, you can use the
Search.runPaged
method instead. This method allows you to handle large result sets by breaking them into smaller, more manageable chunks or pages. Here is an example of how you can use `Search.runPaged`:
Copy code
javascript
var searchObj = search.load({
  id: "customsearch_1",
});
var list = [];
var page;
var pagedData;
var additionalFilterExpression = [
  ["isinactive", "is", "F"],
  "AND",
  ["subsidiary", "anyof", params.subsidiaries],
  "AND",
  ["date", "before", searchDate],
];
if (params.department) {
  additionalFilterExpression.push("AND");
  additionalFilterExpression.push(["department", "is", params.department]);
}
if (params.class) {
  additionalFilterExpression.push("AND");
  additionalFilterExpression.push(["class", "is", params.class]);
}
if (params.location) {
  additionalFilterExpression.push("AND");
  additionalFilterExpression.push(["location", "is", params.location]);
}
searchObj.filterExpression = searchObj.filterExpression.concat(additionalFilterExpression);
pagedData = searchObj.runPaged({pageSize: 1000});
pagedData.pageRanges.forEach(function(pageRange) {
  page = pagedData.fetch({index: pageRange.index});
  page.data.forEach(function(row) {

    list.push({
      a:row.getValue(''),

    })
    return true;
  });
  return true;
});
In this example, the search results are divided into pages of 1000 results each. The
forEach
method is then used to iterate over each page and process the results. Remember to replace
"customsearch_1"
with your actual saved search ID and adjust the filter expressions and the fields you want to retrieve as per your requirements. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.855655074
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.851897597
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.835867822
Please provide your feedback on this answer.