I am trying to send a message based on all of the ...
# suitescript
j
I am trying to send a message based on all of the data from the Reduce stage in a Map/Reduce script. However, summarize is only able to access the last key written in the reduce stage. Is that expected behavior? Shouldn’t I be able to access all items written in
reduce
in this stage?
Copy code
function summarize(context){
    const vendors = {}
    let totalItemsProcessed = 0
    context.output.iterator().each(function(key, row) {
        // only manages to log the very last item written to the context
        log.debug({
            title: 'vendor summary',
            details: key
        })
        // map-reduce scripts always serialize objects to JSON in the context
        vendors[key] = JSON.parse(row)
        totalItemsProcessed++
    })
    const searchDate = new Date();
    const body = JSON.stringify({
        entity: "vendor",
        recently_created: vendors,
        search_date: searchDate
    })
    middlewareRequest(body, "scheduled/Vendor")
    const summaryMessage = "Usage: " + context.usage + " Concurrency: " + context.concurrency +
                " Number of yields: " + context.yields + " Total Items Processed: " + totalItemsProcessed;
    log.audit({
        title: 'Summary of usage',
        details: summaryMessage
    });
}