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 check for the number of 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, unit usage details are displayed 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.

Related Topics

SuiteScript Governance and Limits
SuiteScript 2.x API Governance
Script Type Usage Unit Limits
Governance on Script Logging
Search Result Limits
Script Execution Time Limits

General Notices