Introduction
NetSuite uses a SuiteScript governance model to manage system performance and prevent scripts from consuming excessive resources. Each script type and SuiteScript API consumes a specific number of usage units. Once the script exceeds its allowed units, execution is terminated automatically to protect the system.
If youโve ever faced the SSS_USAGE_LIMIT_EXCEEDED
error, itโs likely your script hit one of these thresholds.
How SuiteScript Governance Works
SuiteScript usage is tracked in two ways:
- By Script Type โ Each type (User Event, Client, Scheduled, Map/Reduce, etc.) has its own time and resource limits.
- By API Call โ Each SuiteScript API method consumes a fixed number of usage units (for example, loading a record uses more than reading a field).
When limits are exceeded, NetSuite automatically stops script execution to prevent performance degradation.
Map/Reduce Script Data Size Limits
Map/Reduce scripts are designed for large-scale data processing, but they also have strict limits on data size:
Constraint | Limit | Error Code |
---|---|---|
Maximum Key Length | 3,000 characters | KEY_LENGTH_IS_OVER_3000_BYTES |
Maximum Value Size | 10 MB | VALUE_LENGTH_IS_OVER_10_MB |
Tip:
When using mapContext.write()
or reduceContext.write()
, keep keys under 3,000 characters and values under 10 MB. Avoid using keys to pass dynamic or long strings โ use values instead.
Common SuiteScript API Governance Units
Below is a reference table of typical governance unit consumption by SuiteScript 2.x APIs.
(Values are approximate and may vary slightly depending on NetSuite release updates.)
SuiteScript API / Action | Module | Typical Governance Units |
---|---|---|
record.load() | N/record | 10 |
record.save() | N/record | 20 |
record.submitFields() | N/record | 5 |
record.delete() | N/record | 20 |
record.copy() | N/record | 10 |
search.create() | N/search | 5 |
search.run() | N/search | 5 |
search.lookupFields() | N/search | 10 |
search.load() | N/search | 5 |
email.send() | N/email | 10 |
file.load() | N/file | 5 |
file.create() | N/file | 10 |
http.get() | N/https | 10 |
http.post() | N/https | 10 |
record.attach() | N/record | 10 |
record.detach() | N/record | 10 |
record.getValue() | N/record | 0 |
record.setValue() | N/record | 0 |
runtime.getCurrentUser() | N/runtime | 0 |
task.create() | N/task | 5 |
task.submit() | N/task | 10 |
format.format() | N/format | 0 |
log.debug() | N/log | 0 |
These numbers help developers design scripts that stay well within usage limits โ particularly important for Scheduled or Map/Reduce scripts handling large data sets.
Script Type Usage Limits (Approximate)
Script Type | Governance Limit (Units) | Execution Time Limit |
---|---|---|
User Event | 1,000 | 10 minutes |
Client Script | 1,000 | User-controlled |
Scheduled Script | 10,000 | 60 minutes |
Map/Reduce (per stage) | 5,000 | Managed by NetSuite |
RESTlet | 5,000 | 5 minutes |
Suitelet | 1,000 | 10 minutes |
Portlet | 1,000 | 10 minutes |
Workflow Action Script | 1,000 | 10 minutes |
Note: When a script exceeds its time or usage threshold, it automatically reschedules (for Map/Reduce) or stops execution.
Error Handling and Governance Enforcement
NetSuite internally detects scripts that might run endlessly or execute excessive loops.
If detected, it throws the error:
SSS_INSTRUCTION_COUNT_EXCEEDED
Indicates a potential infinite loop or unending recursion.
To prevent this:
- Always include loop exit conditions.
- Limit recursion and nested logic.
- Avoid unnecessary
while
loops without termination logic.
Monitoring Script Usage
You can check remaining usage units in your script with:
const runtime = require('N/runtime');
log.debug('Remaining Usage:', runtime.getCurrentScript().getRemainingUsage());
This is especially useful to decide when to reschedule a script or yield control before hitting limits.
Best Practices to Prevent Governance Issues
โ
Batch Processing: Process records in small chunks (for example, 500 per batch).
โ
Avoid Redundant Loads: Only load records when necessary.
โ
Optimize Searches: Use filters, columns, and saved searches instead of large unscripted searches.
โ
Cache Data: Use N/cache
module or temporary variables.
โ
Monitor Logs: Avoid excessive logging that consumes script time.
โ
Use Map/Reduce for Heavy Jobs: They auto-handle concurrency and rescheduling.
Key Takeaway
SuiteScript governance is NetSuiteโs way of balancing performance and stability across accounts.
By understanding usage units, optimizing API calls, and writing efficient scripts, youโll:
- Avoid timeouts and governance errors.
- Improve overall script performance.
- Keep your integrations and automations running smoothly.
Leave a Reply