SuiteScript 2.x Map/Reduce Script Entry Points and API
Map/Reduce Script Entry Points
The map/reduce script type includes four entry points. These entry points let you control both the script’s behavior and the data flow within the map/reduce stages. For an overview of the stages, see Map/Reduce Script Stages.
Entry Point |
Context Object |
Required/Optional |
Description |
---|---|---|---|
Required |
Marks the beginning of the map/reduce script execution. Invokes the input stage. This function is invoked one time in the execution of the script. |
||
Optional, but if this entry point is skipped, the reduce(reduceContext) entry point is required. |
Invokes the map stage. If this entry point is used, the map function is invoked one time for each key-value pair provided by the getInputData(inputContext) function. |
||
Optional, but if this entry point is skipped, the map(mapContext) entry point is required. |
Invokes the reduce stage. If this entry point is used, the reduce function is invoked one time for each key and list of values provided. Data is provided either by the map stage or, if the map stage is not used, by the getInputData stage. |
||
Optional |
Invokes the summarize stage. If the summarize entry point is used, the summarize function is invoked one time in the execution of the script. |
Map/Reduce Script API
The following tables describe properties that are available through the map/reduce entry points.
inputContext Object Members
The following members are called on inputContext.
Member Type |
Name |
Return Type / Value Type |
Description |
---|---|---|---|
Property |
boolean |
Indicates whether the current invocation of the getInputData(inputContext) function represents a restart. |
|
Object |
object |
And object that contains the input data. |
The following members are called on inputContext.ObjectRef.
Member Type |
Name |
Return Type / Value Type |
Description |
---|---|---|---|
Property |
string | number |
The internal ID or script ID of the object. For example, this value could be a saved search ID. |
|
string |
The object’s type. |
mapContext Object Members
The following members are called on mapContext.
Member Type |
Name |
Return Type / Value Type |
Description |
---|---|---|---|
Property |
boolean |
Indicates whether the current invocation of the map(mapContext) function represents a restart. If the value of isRestarted is true, then the function was invoked previously, but unsuccessfully, for the current key-value pair. |
|
property |
Indicates whether the current invocation of the map(mapContext) function represents the first or a subsequent attempt to process the current key-value pair. |
||
iterator |
Holds serialized errors that were thrown during previous attempts to execute the map(mapContext) function on the current key-value pair. |
||
string |
The key to be processed during the current invocation of the map(mapContext) function. |
||
string |
The value to be processed during the current invocation of the map(mapContext) function. |
||
Method |
void |
Writes the map(mapContext) output as key-value pairs. This data is passed to the reduce stage, if the reduce entry point is used, or to the summarize stage. |
reduceContext Object Members
The following members are called on reduceContext.
Member Type |
Name |
Return Type / Value Type |
Description |
---|---|---|---|
Property |
boolean |
Indicates whether the current invocation of the reduce(reduceContext) function represents a restart. If the value of isRestarted is true, then the function was invoked previously, but unsuccessfully, for the current key-value pair. |
|
number |
Indicates whether the current invocation of the reduce(reduceContext) function represents the first or a subsequent attempt to process the current key-value pair. |
||
iterator |
Holds serialized errors that were thrown during previous attempts to execute the reduce(reduceContext) function on the current key and its associated values. |
||
string |
The input key to process during the reduce stage. |
||
string[] |
The key to be processed during the current invocation of the reduce(reduceContext) function. |
||
Method |
void |
Writes the reduce(reduceContext) function as key-value pairs. This data is passed to the summarize stage. |
summaryContext Object Members
The following members are called on the summaryContext.
Member Type |
Name |
Value Type |
Description |
---|---|---|---|
Property |
boolean (read-only) |
Indicates whether the current invocation of the summarize(summaryContext) function represents a restart. If the value of isRestarted is true, then the function was invoked previously, but unsuccessfully. |
|
number |
The maximum concurrency number when running the map/reduce script. |
||
Date |
The time and day when the script began running. |
||
number |
The total number of seconds that elapsed during the processing of the script. |
||
number |
The total number of usage units consumed during the processing of the script. |
||
number |
The total number of yields that occurred during the processing of the script. |
||
object |
Object that contains data about the input stage. |
||
object |
Object that contains data about the map stage. |
||
object |
Object that contains data about the reduce stage. |
||
iterator |
Iterator that contains the keys and values saved as the output of the reduce stage. |
inputSummary Object members
The following members are called on summaryContext.inputSummary.
Member Type |
Name |
Value Type |
Description |
---|---|---|---|
Property |
Date |
The time and day when the getInputData(inputContext) function began running. |
|
string |
Holds serialized errors thrown from the getInputData(inputContext) function. |
||
number |
The total number of seconds that elapsed during execution of the getInputData(inputContext) function. This tally does not include idle time. |
||
number |
The total number of usage units consumed by processing of the getInputData(inputContext) function. |
mapSummary Members
The following members are called on summaryContext.mapSummary.
Member Type |
Name |
Value Type |
Description |
---|---|---|---|
Property |
number |
Maximum concurrency number when running map(mapContext). |
|
Date |
The time and day when the first invocation of map(mapContext) function began. |
||
iterator |
Holds serialized errors thrown during the map stage. |
||
iterator |
Holds the keys passed to the map stage by the getInputData stage. |
||
number |
The total number of seconds that elapsed during the map stage. |
||
number |
The total number of usage units consumed during the map stage. |
||
number |
The total number of yields that occurred during the map stage. |
reduceSummary Members
The following members are called on summaryContext.reduceSummary.
Member Type |
Name |
Value Type |
Description |
---|---|---|---|
Property |
number |
Maximum concurrency number when running reduce(reduceContext). |
|
Date |
The time and day when the first invocation of the reduce(reduceContext) function began. |
||
iterator |
Holds serialized errors thrown during the reduce stage. |
||
iterator |
Holds the keys passed to the reduce stage. |
||
number |
The total number of seconds that elapsed during the reduce stage. |
||
number |
The total number of usage units consumed during the reduce stage. |
||
number |
The total number of yields that occurred during the reduce stage. |