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

getInputData(inputContext)

inputContext

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.

map(mapContext)

mapContext

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.

reduce(reduceContext)

reduceContext

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.

summarize(summaryContext)

summaryContext

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

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 is a restart. If isRestarted is true, that means the function was already called for this key-value pair but didn't finish successfully.

mapContext.executionNo

property

Indicates whether the current run of the map(mapContext) function is the first or a later attempt to process the key-value pair.

mapContext.errors

iterator

Holds serialized errors that were thrown during previous attempts to run 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 key that's being processed in this run of the map(mapContext) function.

Method

mapContext.write(options)

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

reduceContext.isRestarted

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.

reduceContext.executionNo

number

Indicates whether the current run of the reduce(reduceContext) function is the first or a later attempt to process the key-value pair.

reduceContext.errors

iterator

Holds serialized errors that were thrown during previous attempts to run 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 being processed in this run of the reduce(reduceContext) function.

Method

reduceContext.write(options)

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

summaryContext.isRestarted

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.

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 time in seconds the script took to run.

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 with data about the input stage.

summaryContext.mapSummary

object

Object with data about the map stage.

summaryContext.reduceSummary

object

Object with data about the reduce stage.

summaryContext.output

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

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 time in seconds for the getInputData(inputContext) function run (not counting 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 time in seconds the map stage took.

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 time in seconds the reduce stage took.

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