Map/Reduce Script Stages

The map/reduce script type goes through at least two of five possible stages.

The stages are processed in the following order. Each stage must finish before the next one starts.

Note:

You don't need to use both the map and reduce stages. You can skip one of them.

The following diagram illustrates these stages, in the context of processing a set of invoices.

Here's how the stages are used in this example:

For a code sample similar to this example, see Processing Invoices Example.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

Passing Data to a Map or Reduce Stage

To avoid changing data accidentally, key-value pairs are converted to strings when passed between stages. For map/reduce scripts, SuiteScript 2.x checks if the data is a string and uses JSON.stringify() to convert it if needed.

JSON-serialized objects stay in JSON format. To avoid possible errors, SuiteScript does not automatically deserialize the data. For instance, trying to convert non-JSON data types like CSV or XML can cause errors. You can use JSON.parse() to convert the JSON string back to a JS object if you need to.

Map/reduce script keys (specifically, in mapContext or reduceContext objects) have a 3,000 character limit. In addition, error messages are returned when a key is longer than 3,000 characters or a value is larger than 10 MB. Keys over 3,000 characters return a KEY_LENGTH_IS_OVER_3000_BYTES error. Values over 10 MB return a VALUE_LENGTH_IS_OVER_10_MB error.

If you have map/reduce scripts that use the mapContext.write(options) or reduceContext.write(options) methods, keep key strings under 3,000 characters and value strings under 10 MB. Consider the potential length of dynamically generated strings, which might exceed these limits. Also, try not to use keys instead of values to pass your data.

For more information about map/reduce limits see Map/Reduce Governance.

Related Topics

General Notices