To monitor system resource usage in NetSuite scripts, use the getRemainingUsage() function. This function tells you how many governance units are left for your script, helping prevent errors and optimize performance.
define([‘N/runtime’, ‘N/log’], function(runtime, log) {
function executeScript(context) {
let remainingUnits = runtime.getCurrentScript().getRemainingUsage();
log.debug(‘Remaining Governance Units’, remainingUnits);
if (remainingUnits < 100) {
log.debug(‘Low Governance Units’, ‘Consider rescheduling the script.’);
}
// Your script logic here
}
return {
execute: executeScript
};
});
How It Works
Load the runtime and log modules.
Use runtime.getCurrentScript().getRemainingUsage() to get remaining units.
Log the remaining units.
Add logic to handle low units if needed.
By using getRemainingUsage(), you can ensure your NetSuite scripts run efficiently without exceeding resource limits.