SuiteScript 2.x Map/Reduce Script Entry Points and API
Map/Reduce Script Entry Points
The map/reduce script type has four entry points. These let you control the script's behavior and 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 and 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 you use this entry point, 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 you use this entry point, the reduce function is invoked one time for each key and list of values provided. Data comes from the map stage or, if that's not used, from the getInputData stage. |
||
Optional |
Invokes the summarize stage. If you use this entry point, 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 is a restart. If isRestarted is true, that means the function was already called for this key-value pair but didn't finish successfully. |
|
property |
Indicates whether the current run of the map(mapContext) function is the first or a later attempt to process the key-value pair. |
||
iterator |
Holds serialized errors that were thrown during previous attempts to run 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 key that's being processed in this run of the map(mapContext) function. |
||
Method |
void |
Writes the map(mapContext) output as key-value pairs. This data goes to the reduce stage (if it's used), or straight 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 is a restart. If isRestarted is true, the function was called before for this key-value pair but didn't finish successfully. |
|
number |
Indicates whether the current run of the reduce(reduceContext) function is the first or a later attempt to process the key-value pair. |
||
iterator |
Holds serialized errors that were thrown during previous attempts to run 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 being processed in this run of the reduce(reduceContext) function. |
||
Method |
void |
Writes the reduce(reduceContext) function as key-value pairs. This data goes 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 is a restart. If isRestarted is true, the function was run before but didn't finish successfully. |
|
number |
The maximum concurrency number when running the map/reduce script. |
||
Date |
The time and day when the script began running. |
||
number |
The total time in seconds the script took to run. |
||
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 with data about the input stage. |
||
object |
Object with data about the map stage. |
||
object |
Object with data about the reduce stage. |
||
iterator |
Iterator with the keys and values saved from the reduce stage output. |
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 time in seconds for the getInputData(inputContext) function run (not counting 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 time in seconds the map stage took. |
||
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 time in seconds the reduce stage took. |
||
number |
The total number of usage units consumed during the reduce stage. |
||
number |
The total number of yields that occurred during the reduce stage. |