In order to use getRange for handling the large number of results, we will have to consider the following:
// Assume that 'N/search' module is included as 'search'
// this search will return a lot of results (not having any filters)
var s = search.create({
type: search.Type.TRANSACTION,
columns : ['entity','amount'],
filters: []
});
var resultSet = s.run();
// now take the first portion of data.
var currentRange = resultSet.getRange({
start : 0,
end : 1000
});
var i = 0; // iterator for all search results
var j = 0; // iterator for current result range 0..999
while ( j < currentRange.length ) {
// take the result row
var result = currentRange[j];
// and use it like this....
var transId = result.id;
var entityId = result.getValue('entity');
var entityName = result.getText('entity');
var amount = result.getValue('amount');
// finally:
i++; j++;
if( j==1000 ) { // check if it reaches 1000
j=0; // reset j an reload the next portion
currentRange = resultSet.getRange({
start : i,
end : i+1000
});
}
}
Lets calculate the Governance. We have 1 + count/1000 getRange calls taking 10 units each, so:
G = (1 + count/1000 ) * 10
Example: 9500 rows will take 100 units