Introduction
If youβve ever seen an error like βSSS_USAGE_LIMIT_EXCEEDEDβ, youβve hit one of NetSuiteβs built-in guardrails: governance.
NetSuite enforces strict governance limits on all SuiteScripts to protect system performance. Each API call consumes βusage units,β and exceeding these limits causes your script to stop abruptly.
In this post, youβll learn:
- What governance is and why it exists.
- Common causes of timeouts.
- How to monitor and reset governance.
- Practical optimization techniques and code patterns.
What Is SuiteScript Governance?
SuiteScript governance controls how much processing power each script can use. Every record operation, search, or email consumes a specific number of usage units.
When a script exceeds its allotted units, it stops with an error β even if only one record was left to process.
| Script Type | Governance Limit (approx.) |
|---|---|
| User Event | 1,000 units |
| Client Script | Unlimited (runs in browser) |
| Scheduled Script | 10,000 units |
| Map/Reduce (per stage) | 10,000 units |
| Suitelet | 1,000 units |
Common Causes of Timeouts
- Large Saved Searches or Record Loops β running through thousands of results without yielding.
- Nested Record Loads or Saves β loading multiple related records within a loop.
- Excessive Logging β
log.debug()in loops adds overhead. - Not Yielding in Scheduled or Map/Reduce Scripts β failing to yield and resume.
Monitoring Governance Units
You can check remaining governance units anytime:
var remaining = runtime.getCurrentScript().getRemainingUsage();
log.debug('Remaining governance units', remaining);
Use this strategically inside loops to decide when to yield or reschedule.
How to Avoid Timeouts
1οΈβ£ Use Search Paginators
Instead of loading all results at once:
var pagedData = search.load({id: 'customsearch_my_search'}).runPaged({pageSize: 1000});
pagedData.pageRanges.forEach(function(pageRange){
var page = pagedData.fetch({index: pageRange.index});
page.data.forEach(function(result){
// process result
});
});
2οΈβ£ Move Heavy Logic to Map/Reduce
Use Map/Reduce for large-volume operations. It automatically yields and scales across multiple queues.
3οΈβ£ Avoid Unnecessary Record Loads
Use record.submitFields() instead of full record load:
record.submitFields({
type: record.Type.SALES_ORDER,
id: soId,
values: { custbody_processed: true }
});
4οΈβ£ Cache Reusable Data
Cache lookups or configuration data using script parameters or custom records instead of repeated searches.
5οΈβ£ Yield Early and Often
In Scheduled Scripts:
if (runtime.getCurrentScript().getRemainingUsage() < 200) {
script.yield();
}
6οΈβ£ Optimize Saved Searches
- Filter out unused fields.
- Limit results by date or status.
- Use indexed fields for faster queries.
Debugging Governance Errors
Typical errors include:
SSS_USAGE_LIMIT_EXCEEDEDβ exceeded governance units.SSS_TIME_LIMIT_EXCEEDEDβ script ran too long.UNEXPECTED_ERRORβ often caused by nested record access or missing yields.
To debug:
- Add checkpoints using
log.audit()for every major step. - Capture remaining units regularly.
- Move repetitive logic into helper functions.
Example: Rescheduling a Script Automatically
define(['N/runtime', 'N/task'], function(runtime, task) {
function execute(context) {
var script = runtime.getCurrentScript();
if (script.getRemainingUsage() < 200) {
var rescheduleTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: script.id,
deploymentId: script.deploymentId
});
rescheduleTask.submit();
return;
}
// Continue processing...
}
return { execute: execute };
});
This ensures that your process continues seamlessly instead of failing.
Best Practices Recap
β
Use Map/Reduce for heavy loads.
β
Always monitor getRemainingUsage().
β
Replace record.load() with submitFields() when possible.
β
Batch saved searches with pagination.
β
Avoid infinite loops or unnecessary record access.
β
Log only essential information.
Conclusion
NetSuiteβs governance model may seem restrictive, but it enforces efficient, scalable development. By writing optimized scripts and handling yields or reschedules properly, youβll keep your processes running smoothly β even when dealing with thousands of records.
Learn more about NetSuite Scripting Tutorials & different NetSuite Customization resources
Discover more from The NetSuite Pro
Subscribe to get the latest posts sent to your email.
Leave a Reply