Monitoring Script Usage
You can monitor SuiteScript unit usage using the Script.getRemainingUsage() method as shown in the following examples.
Example 1
This example shows how to instantiate the current script object and call Script.getRemainingUsage() to write the script's remaining usage units to the execution log.
var scriptObj = runtime.getCurrentScript();
log.debug({
title: "Remaining usage units: ",
details: scriptObj.getRemainingUsage()
});
Example 2
This example shows how to instantiate the current script object and checks the remaining usage units. If there are more than 50 usage units remaining, the script will execute a certain set of instructions.
var scriptObj = runtime.getCurrentScript();
var unitsRemaining = scriptObj.getRemainingUsage();
if (unitsRemaining > 50)
{
//execute code here
}
You can also monitor script unit usage by running the script in the SuiteScript Debugger. After a script completes execution, you can view unit usage details on the Execution Log tab in the SuiteScript Debugger console. If usage units are exceeded, usage limit error messages are emailed to the script owner indicating the number of usage units that were executed in the script before the usage limit error occurred.
For more information about the SuiteScript Debugger, see the help topic SuiteScript Debugger.