Overview
Every SuiteScript in NetSuite operates under a governance model that limits how many usage units a script can consume during execution. These limits vary depending on the script type, ensuring that no single script monopolizes system resources.
If a script exceeds its allocated usage units, NetSuite automatically terminates execution β commonly throwing an error such as SSS_USAGE_LIMIT_EXCEEDED
.
You can check the remaining units in your script using:
const runtime = require('N/runtime');
log.debug('Remaining Usage:', runtime.getCurrentScript().getRemainingUsage());
SuiteScript Usage Unit Limits by Script Type
The following table summarizes the maximum allowable usage units for each SuiteScript type in both SuiteScript 1.0 and 2.x:
Script Type | SuiteScript Version | Total Usage Units Allowed | Notes / Recommendations |
---|---|---|---|
Bundle Installation Scripts | 1.0 / 2.x | 10,000 | Each bundle installation execution is limited to 10,000 units. |
Client Scripts | 1.0 / 2.x | 1,000 | Measured per script. Form-level and record-level scripts have independent limits of 1,000 each. |
Custom Tool Scripts | 2.1 | 1,000 | Applies to each tool execution. |
Map/Reduce Scripts | 2.x only | Dynamic | No fixed overall limit; each map/reduce stage (getInputData, map, reduce, summarize) has isolated usage tracking. |
Mass Update Scripts | 1.0 / 2.x | 1,000 | 1,000 units per record or per execution. |
Portlet Scripts | 1.0 / 2.x | 1,000 | Use lightweight code to maintain dashboard responsiveness. |
RESTlets | 1.0 / 2.x | 5,000 | Governed at both API and script level. Ideal for integrations; see RESTlet Governance for details. |
Scheduled Scripts | 1.0 / 2.x | 10,000 | All combined actions within a single run cannot exceed 10,000 units. Consider Map/Reduce for long-running jobs. |
SDF Installation Scripts | 2.x | 10,000 | Limit per execution of SDF deployment. |
Suitelets | 1.0 / 2.x | 1,000 | 1,000 units per Suitelet execution. Optimize for fast UI response to prevent poor user experience. |
User Event Scripts | 1.0 / 2.x | 1,000 | Executed on record create/edit/delete. Keep code minimal for responsiveness. |
Workflow Action Scripts (Custom Actions) | 1.0 / 2.x | 1,000 | 1,000 units per workflow state; ensure heavy logic is separated from workflow triggers. |
Core Plug-ins | Varies | Up to 10,000 | Default limit unless otherwise specified per plug-in. |
Custom Plug-ins | Any | 10,000 | Each plug-in instance limited to 10,000 units per execution. |
SSP Application Scripts | SSP / SuiteCommerce | 1,000 | Governed by SSP Application Governance rules. |
SuiteScript Debugger | β | 1,000 | When debugging, scripts are limited to 1,000 usage units. |
Choosing the Right Script Type
Different script types are optimized for different tasks.
Below are some quick guidelines:
Scenario | Recommended Script Type | Why |
---|---|---|
Processing large data sets | Map/Reduce | Automatically handles rescheduling and parallel processing. |
User-triggered field logic | Client or User Event | Runs in response to user actions. |
Custom web forms | Suitelet | Provides dynamic server-side UI and logic. |
Scheduled background tasks | Scheduled Script | Best for recurring jobs under 10,000 usage units. |
Integrations / external APIs | RESTlet | Handles REST-based communication securely. |
When to Use Map/Reduce Instead of Scheduled Scripts
If your scheduled script regularly approaches 10,000 usage units, you should migrate to a Map/Reduce script.
Why:
- Each stage runs independently with its own usage limit.
- Automatic yielding and rescheduling built in.
- Handles large data volumes efficiently without hitting timeouts.
Example:
if (runtime.getCurrentScript().getRemainingUsage() < 200) {
task.create({ taskType: task.TaskType.MAP_REDUCE }).submit();
}
Best Practices for Staying Within Usage Limits
β
Batch Processing: Work in small record sets (e.g., 500 records per iteration).
β
Minimize Record Loads: Use search.lookupFields()
or cached data.
β
Optimize Client Scripts: Avoid unnecessary logging or loops.
β
Monitor Usage: Log remaining usage regularly during execution.
β
Use Asynchronous Types (Map/Reduce, RESTlets): For long-running jobs.
β
Avoid Large Inline Searches: Use Saved Searches or Map/Reduce getInputData.
β
Reschedule Proactively: Before hitting thresholds in scheduled scripts.
Key Takeaways
- Each SuiteScript type in NetSuite has its own usage unit threshold.
- Exceeding this limit causes termination and potential errors.
- Use
getRemainingUsage()
and efficient coding practices to stay under governance. - Choose the appropriate script type (Map/Reduce, RESTlet, Scheduled) based on your task scale and performance needs.
Leave a Reply