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.
Discover more from The NetSuite Pro
Subscribe to get the latest posts sent to your email.
Leave a Reply