SuiteScript provides developers with the flexibility to customize NetSuite extensively. However, beyond familiarity with SuiteScript modules, understanding the concept of governance is crucial for developers to optimize their scripts effectively.
According to the official NetSuite documentation:
“To optimize application performance, NetSuite uses a SuiteScript governance model based on usage units. If the number of allowable usage units is exceeded, the script execution is terminated.” (Source)
In simple terms, governance refers to the system that limits script usage units. Many SuiteScript module methods require server responses, which can take time and add load to the server.
To ensure users receive results promptly and to protect server performance from heavy requests, NetSuite has implemented the “governance” model with specific rules and limitations.
SuiteScript offers various script types tailored for different scenarios.
Each script type has a distinct governance limit based on its intended use case.
Map/Reduce scripts, introduced in SuiteScript 2.x, are ideal for handling large-scale data updates and manipulations. Unlike other script types, they don’t have a fixed governance limit for a single execution.
However, they still operate within governance constraints, as each stage of a Map/Reduce script has its own limitations. A Map/Reduce script is divided into four stages:
- getInputData
- map
- reduce
- summarize
Each stage has its own governance limit per single execution. Depending on the getInputData stage, multiple executions of the map and reduce stages might occur. Here are the limits for each stage per single execution:
- getInputData: 10,000 units
- map: 1,000 units
- reduce: 5,000 units
- summarize: 10,000 units
If you need to process large batches of data, Map/Reduce scripts are an excellent choice due to their scalability and higher governance capacities compared to other script types.
You can refer to the official documentation to check the governance usage cost for each API call.
Once your script is complete, you can use the N/runtime module to monitor remaining governance units at runtime. Here’s a sample snippet:
require(['N/runtime', 'N/log'], function(runtime, log) {
const currentScript = runtime.getCurrentScript();
log.debug('Check Governance', 'Remaining governance units: ' + currentScript.getRemainingUsage()); // For server-side scripts
console.log('Remaining governance units: ' + currentScript.getRemainingUsage()); // For client-side scripts
});
Ensure you use the appropriate logging method for your script type (log.debug for server-side and console.log for client-side). When executed, the remaining governance units will be displayed as a numeric value, such as:
Remaining governance units: 990
Governance is not just a limitation but also a helpful indicator for developers. If your script consumes excessive governance units, it may be time to review and refactor the script to improve its efficiency.
Pay close attention to governance limits, especially when processing large datasets. Excessive API calls may make the script exceeds governance thresholds.
Understanding governance limits will help you choose the appropriate script type, design efficient script flows, and confidently handle the data your script needs to process.
About Us
Concentrus is a leading provider of innovative cloud-based enterprise resource planning (ERP) solutions, including NetSuite. Our team of NetSuite experts offers a range of services, including NetSuite price analysis, NetSuite training, and NetSuite integration services.
Our goal is to help businesses of all sizes maximize their investment in NetSuite by providing expert NetSuite cost optimization and implementation strategies. With years of experience as a NetSuite partner, our NetSuite administrators and NetSuite consultants are well equipped to help businesses of all sizes with their NetSuite consulting needs.
Whether you're looking for a NetSuite consultant to help with your NetSuite implementation or you need ongoing NetSuite support, Concentrus is here to help.
Read About Our Implementation Methodology
Want more NetSuite Tips and Tricks? Check out our Short & 'Suite videos