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

getInputData(inputContext)

inputContext

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.

map(mapContext)

mapContext

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.

reduce(reduceContext)

reduceContext

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.

summarize(summaryContext)

summaryContext

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

inputContext.isRestarted

boolean

Indicates whether the current invocation of the getInputData(inputContext) function represents a restart.

Object

inputContext.ObjectRef

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

ObjectRef.id

string | number

The internal ID or script ID of the object. For example, this value could be a saved search ID.

ObjectRef.type

string

The object’s type.

mapContext Object Members

The following members are called on mapContext.

Member Type

Name

Return Type / Value Type

Description

Property

mapContext.isRestarted

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.

mapContext.executionNo

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.

mapContext.errors

iterator

Holds serialized errors that were thrown during previous attempts to execute the map(mapContext) function on the current key/value pair.

mapContext.key

string

The key to be processed during the current invocation of the map(mapContext) function.

mapContext.value

string

The value to be processed during the current invocation of the map(mapContext) function.

Method

mapContext.write(options)

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

reduceContext.isRestarted

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.

reduceContext.executionNo

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.

reduceContext.errors

iterator

Holds serialized errors that were thrown during previous attempts to execute the reduce(reduceContext) function on the current key and its associated values.

reduceContext.key

string

The input key to process during the reduce stage.

reduceContext.values

string[]

The key to be processed during the current invocation of the reduce(reduceContext) function.

Method

reduceContext.write(options)

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

summaryContext.isRestarted

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.

summaryContext.concurrency

number

The maximum concurrency number when running the map/reduce script.

summaryContext.dateCreated

Date

The time and day when the script began running.

summaryContext.seconds

number

The total number of seconds that elapsed during the processing of the script.

summaryContext.usage

number

The total number of usage units consumed during the processing of the script.

summaryContext.yields

number

The total number of yields that occurred during the processing of the script.

summaryContext.inputSummary

object

Object that contains data about the input stage.

summaryContext.mapSummary

object

Object that contains data about the map stage.

summaryContext.reduceSummary

object

Object that contains data about the reduce stage.

summaryContext.output

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

inputSummary.dateCreated

Date

The time and day when the getInputData(inputContext) function began running.

inputSummary.error

string

Holds serialized errors thrown from the getInputData(inputContext) function.

inputSummary.seconds

number

The total number of seconds that elapsed during execution of the getInputData(inputContext) function. This tally does not include idle time.

inputSummary.usage

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

mapSummary.concurrency

number

Maximum concurrency number when running map(mapContext).

mapSummary.dateCreated

Date

The time and day when the first invocation of map(mapContext) function began.

mapSummary.errors

iterator

Holds serialized errors thrown during the map stage.

mapSummary.keys

iterator

Holds the keys passed to the map stage by the getInputData stage.

mapSummary.seconds

number

The total number of seconds that elapsed during the map stage.

mapSummary.usage

number

The total number of usage units consumed during the map stage.

mapSummary.yields

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

reduceSummary.concurrency

number

Maximum concurrency number when running reduce(reduceContext).

reduceSummary.dateCreated

Date

The time and day when the first invocation of the reduce(reduceContext) function began.

reduceSummary.errors

iterator

Holds serialized errors thrown during the reduce stage.

reduceSummary.keys

iterator

Holds the keys passed to the reduce stage.

reduceSummary.seconds

number

The total number of seconds that elapsed during the reduce stage.

reduceSummary.usage

number

The total number of usage units consumed during the reduce stage.

reduceSummary.yields

number

The total number of yields that occurred during the reduce stage.

General Notices