DEV Community

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

Posted on

2

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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more