DEV Community

Cover image for SuiteScript 2.0 - Using Map-Reduce to retrieve large set of records.
Erick
Erick

Posted on

SuiteScript 2.0 - Using Map-Reduce to retrieve large set of records.

If you've noticed, Netsuite is very controlled in how they allow partners access their data without safeguards. And trying to collect large sets of data or process them can be tough but with a little bit of ingenuity, you can.

This script is a Map/Reduce script, which is a type of script that allows you to process large amounts of data in smaller chunks.

Here is a SuiteScript 2.0 script that retrieves all customer records from NetSuite and logs the internal ID and company name for each record:

/**
 * @NApiVersion 2.x
 * @NScriptType MapReduceScript
 */
define(['N/search'], function(search) {
    function getInputData() {
        var customerSearch = search.create({
            type: search.Type.CUSTOMER,
            columns: ['internalid', 'companyname']
        });
        return customerSearch;
    }

    function map(context) {
        var searchResult = JSON.parse(context.value);
        log.debug({
            title: 'Customer Record',
            details: 'Internal ID: ' + searchResult.values['internalid'].value + ', Company Name: ' + searchResult.values['companyname'].value
        });
    }

    return {
        getInputData: getInputData,
        map: map
    };
});
Enter fullscreen mode Exit fullscreen mode

The script uses the search module to create a search for customer records and retrieve the internal ID and company name for each record. The map function is then used to iterate through the search results and log the internal ID and company name for each record.

This code snippet can be helpful for retrieving large amount of data and customizing the output in NetSuite.

Top comments (0)