In SS2.0 when you have more than 4k search results...
# suitescript
j
In SS2.0 when you have more than 4k search results is there any reason to use runPaged vs repeatedly calling getRange?
Copy code
var sea = search.create();
var pagedResults = sea.runPaged({
	pageSize: 1000
});
pagedResults.pageRanges.forEach(function(range) {
	var page = pagedResults.fetch({
		index: range.index
	});
	page.data.forEach(...);
});
vs something like
Copy code
var sea = search.create();
var resultSet = sea.run();
var i = 0;
while(true) {
    var results = resultSet.getRange({ start: i, end: i + 1000 });
    results.forEach(...);
    if (results.length < 1000) {
        break;
    }
    i += 1000;
}
b
Search.runPaged: 5 units, PagedData.fetch: 5 units ResultSet.getRange: 10 units paged searches will cost less governance points since fetching data is 5 points per 1000 results vs 10 points per 1000 points
j
thanks
had a script using a search that for 99.9% of customers in the account returns <100 results and thought it was fine to use run().each() but for one customer returns almost 6k
a
why not use a map/reduce script where the limit doesn't matter ?
j
It's in a beforeLoad user event on customer support case records to calculate some data for users editing the record
e
I found runPaged to be more performant