reduceContext.errors
Property Description |
Holds errors thrown during earlier tries to run the reduce function for this key and its values. This iterator may also hold the For an overview of events that can cause the map function to be invoked multiple times for a key-value pair, see System Response After a Map/Reduce Interruption. |
Type |
iterator |
Since |
2018.1 |
Members
Member |
Type |
Required/Optional |
Description |
---|---|---|---|
iterator().each(parameters) |
function |
required |
Executes one time for each error. |
parameters
Member |
Type |
Required/Optional |
Description |
---|---|---|---|
iteratorFunction(key, error, executionNo) See also functionParameters. |
function |
required |
Provides logic to be executed during each iteration. |
functionParameters
Parameter |
Type |
Required/Optional |
Description |
---|---|---|---|
key |
string |
optional |
The key-value pair the reduce function was trying to process when the error occurred. |
error |
string |
optional |
A serialization of the error thrown. |
executionNo |
number |
optional |
Shows if the error occurred on the first attempt or a later try to process the key. |
Syntax
The following snippets shows three ways you could use this iterator.
This code isn't a functional example. For a complete script sample, see SuiteScript 2.x Map/Reduce Script Code Samples.
//Add additional code
...
// Create a log entry showing each full serialized error, and the corresponding key.
context.errors.iterator().each(function (key, error, executionNo){
log.error({
title: 'Reduce error for key: ' + key + ', execution no ' + executionNo,
details: error
});
return true;
});
// Log only the name and description of each error thrown.
context.errors.iterator().each(function (key, error, executionNo){
var errorObject = JSON.parse(error);
log.error({
title: 'Reduce error for key ' + key + ', execution no. ' + executionNo,
details: errorObject.name + ': ' + errorObject.message
});
return true;
});
// Calculate and log the number of errors encountered.
var errorCount = 0;
context.errors.iterator().each(function() {
errorCount ++;
return true;
});
log.audit ({
title: 'Errors for reduce key: ' + context.key,
details: 'Total number of errors: ' + errorCount
});