I wrote a script (below) a couple years ago (haven't been coding since - so there is a fair amount or rust ;D) where the ResultSet now exceeds 4000 records which was not anticipated when the script was written. The error is below:
{"type":"error.SuiteScriptError","name":"SSS_SEARCH_FOR_EACH_LIMIT_EXCEEDED","message":"No more than 4000 search results may be returned at one time from nlobjSearchResultSet.forEachResult(callback). Please revise your search criteria or modify the callback logic so that no more than 4000 results are returned."...
Is the best way to fix this to use a different technique (like Map/Reduce - which I'd have to learn now), or is there a way to filter the search so only a certain number of results are returned from the search and the rest of the records get returned/processed in a subsequent execution?
Thanks
//...
invoiceSearch.run().each(function(result) {
// ensure script usage okay
if (usageOkay()) {
entityID = result.getValue({
'name': 'internalid',
'join': 'customer',
'summary': search.Summary.GROUP
});
var maxAmountCustomerRecord = result.getValue({
'name': 'custentity_amount_maxorder_2years',
'join': 'customer',
'summary': search.Summary.GROUP
});
var maxAmountCalculated = result.getValue({
'name': 'formulacurrency',
'formula': 'CASE WHEN {closedate} >= ADD_MONTHS(SYSDATE, -(12 * 2)) THEN {amount} ELSE NULL END',
'summary': search.Summary.MAX
});
// in case the calculated amount is null then make it 0
maxAmountCalculated = maxAmountCalculated || 0.0;
// Only write to the customer record when a change is required
if (maxAmountCustomerRecord != maxAmountCalculated) {
updateRecord(entityID, maxAmountCalculated);
log.debug('Updating customer with entityID: ' + entityID + ', to maxAmount: ' +
maxAmountCalculated + ', from previous value of ' + maxAmountCustomerRecord);
}
return true;
}
else {
// If remaining script usage low, reschedule script
rescheduleScript(entityID);
}
});
//....