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

Erick @smith288

About: I’m a self taught hack. I’ve been known to use a goto statement. I don’t take myself too seriously and I don’t expect you to take me too seriously. If I’m wrong or suck, I have thick skin.

Location:
United States
Joined:
Sep 21, 2018

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

Publish Date: Jan 19 '23
2 0

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.

Comments 0 total

    Add comment