When building automation in NetSuite, one common design decision is choosing the right script type for processing records in the background. Two of the most common options are Scheduled Scripts and Map/Reduce Scripts.
Both can be useful, but they are not designed for exactly the same type of work. Choosing the right one can make a big difference in performance, maintainability, and long-term reliability.
What Are Scheduled Scripts and Map/Reduce Scripts?
A Scheduled Script runs in the background and is typically used to process logic without direct user interaction.
It is often used for tasks such as:
- batch updates
- recurring background processing
- cleanup jobs
- record maintenance
- scheduled calculations
A Map/Reduce Script is also used for background processing, but it is designed for larger and more structured data processing.
It breaks work into stages, which can make it more effective for handling higher record volumes and more complex batch logic.
Why Does the Choice Matter?
Choosing the right script type can help:
- improve processing efficiency
- reduce script failures
- handle larger data sets more cleanly
- simplify maintenance
- reduce governance issues
- make troubleshooting easier
Using the wrong model can lead to unnecessary complexity or weaker performance than needed.
When a Scheduled Script Is a Good Fit
A Scheduled Script is usually a good choice when the job is straightforward and does not need a staged processing model.
Common examples include:
- updating a limited group of records
- running a nightly cleanup task
- recalculating a small set of values
- triggering a recurring maintenance process
- handling a simple background task with clear logic
A Scheduled Script is often easier to build when the process is linear and the volume is manageable.
When Map/Reduce Is a Good Fit
A Map/Reduce Script is usually a better choice when processing is larger, more repetitive, or more structured.
Common examples include:
- processing large result sets
- handling batch updates across many records
- grouping work by key
- processing data in stages
- reducing the risk of large single-run workloads
- managing more complex record processing flows
Map/Reduce is especially useful when a process naturally fits a sequence such as:
- gather records
- process them individually or by group
- summarize the results
Example
A company wants to update a small group of customer records once per day.
If the logic is simple and the record count is limited, a Scheduled Script may be enough.
But if the company needs to process thousands of transaction records, group them by customer, and apply calculated updates across stages, Map/Reduce is usually the better choice.
Sample Scripts
Below is a simple Map/Reduce example that updates customers returned by a saved search:
Map Reduce Script:
/**
* @NApiVersion 2 .1
* @NScriptType MapReduceScript
*/
define(['N/search', 'N/record', 'N/log'], (search, record, log) => {
const CUSTOMER_SEARCH_ID = 'customsearch_customers_to_update';
function getInputData() {
return search.load({
id: CUSTOMER_SEARCH_ID
});
}
function map(context) {
const result = JSON.parse(context.value);
const customerId = result.id;
try {
record.submitFields({
type: record.Type.CUSTOMER,
id: customerId,
values: {
comments: 'Updated by Map/Reduce Script'
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
context.write({
key: 'success',
value: customerId
});
} catch (error) {
log.error({
title: `Error Updating Customer ${customerId}`,
details: error
});
}
}
function summarize(summary) {
log.audit({
title: 'Map/Reduce Complete',
details: {
usage: summary.usage,
yields: summary.yields,
concurrency: summary.concurrency
}
});
}
return {
getInputData,
map,
summarize
};
});
Scheduled Script:
/**
* @NApiVersion 2 .1
* @NScriptType ScheduledScript
*/
define(['N/search', 'N/record', 'N/log'], (search, record, log) => {
const CUSTOMER_SEARCH_ID = 'customsearch_customers_to_update';
function execute(context) {
try {
const customerSearch = search.load({
id: CUSTOMER_SEARCH_ID
});
let processedCount = 0;
customerSearch.run().each(result => {
const customerId = result.id;
try {
record.submitFields({
type: record.Type.CUSTOMER,
id: customerId,
values: {
comments: 'Updated by Scheduled Script'
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
processedCount++;
} catch (error) {
log.error({
title: `Error Updating Customer ${customerId}`,
details: error
});
}
return true;
});
log.audit({
title: 'Scheduled Script Complete',
details: `Total customers updated: ${processedCount}`
});
} catch (error) {
log.error({
title: 'Scheduled Script Failed',
details: error
});
}
}
return { execute };
});
Questions to Ask Before Choosing
Before selecting the script type, it helps to ask:
- How many records need to be processed?
- Is the process simple and linear, or staged and grouped?
- Will the workload grow over time?
- Does the job need structured batch handling?
- Is the script likely to face governance pressure with larger data sets?
- Will the result be easier to maintain in a staged model?
These questions can help guide the choice.
General Rule of Thumb
Use a Scheduled Script when:
- the task is smaller
- the logic is straightforward
- the processing path is mostly linear
- the workload is easier to handle in one background job
Use Map/Reduce when:
- the task processes larger data volumes
- the work can be broken into stages
- records need to be processed repeatedly or in groups
- the design benefits from a more scalable processing model
Tips
- start with the simplest model that fits the requirement
- do not use Map/Reduce unless the process benefits from staged processing
- do not force large-volume jobs into a simple scheduled design
- estimate future growth, not just current volume
- review maintainability before deciding
- test processing behavior in sandbox
Best Practices
- use Scheduled Scripts for smaller and simpler background jobs
- use Map/Reduce for higher-volume or staged processing needs
- design with record volume in mind
- keep processing logic clear and organized
- avoid overcomplicating small jobs
- monitor performance and execution behavior during testing
- document why the selected script type was chosen
References
- SuiteAnswer Article: Map/Reduce Script Best Practices (ID: 106370)
- SuiteAnswer Article: Scheduled Script Best Practices (ID: 10291)
Summary
Choosing between Map/Reduce and Scheduled Scripts in NetSuite depends on the type of work being done. Scheduled Scripts are often a strong fit for simple background tasks, while Map/Reduce is better suited for larger, more structured processing.
The best choice is the one that matches the workload, the processing pattern, and the long-term support needs of the solution.
DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.