Pass a value from the Reduce entry point to the Summarize entry point

In NetSuite, you can use SuiteScript to write custom MapReduce scripts that process large amounts of data.

To pass a value from the Reduce entry point to the Summarize entry point in a NetSuite MapReduce script, here is the same code.

Reduce entry point:

    const reduce = (reduceContext) => {
            try {

                    let reduceObj = {};
                    reduceObj.itemname = itemName;
                    reduceObj.id = itemId;

                    reduceContext.write({
                        key: 1,
                        value: reduceObj
                    });
                }
            } catch (e) {
                log.debug("Error @ Reduce", e);
            }
        }

Summarize entry point:

const summarize = (summaryContext) => {
            try {

                summaryContext.output.iterator().each(function (key, value) {
                    log.debug('value', value);
                  let itemObj = JSON.parse(value)
                    
                    return true;
                });
            } catch (e) {
                log.error({
                    title: e.name,
                    details: e
                });
            }
        }

Leave a comment

Your email address will not be published. Required fields are marked *