• : 1-877-596-8218
  • : sales@aecc.ca
# # #
#

SuiteScript Metering Governance Issue & Recommendations.

SuiteScript Metering/Governance Issue

NetSuite implements a concept of SuiteScript governance to optimize the application performance and the response time. Each API has its time unit consumption and each type of SuiteScript has their own time unit limitation.

For the user event script, client side script, and the SuiteLet, they have a maximum of 1000 time unit allowed. For scheduled script, it has max of 10,000 time unit. If the running SuiteScript exceeds the allowable time unit, it will be stopped.

People who develops the suiteScript need to take this metering issue into consideration, especially for those who are writing script that process more than one record or process data from the search results.

The most common case that the suiteScript exceeds the time unit limitation is the scheduled script, since scheduled script often process large amount of data in the system. To avoid the governance issue, we need to check the remaining time unit usage by using the API:

 

nlapiGetContext().getRemainingUsage()

This API will return the remaining time unit for the schedule script. If the remaining time unit is less than a threshold value, the scheduled be script should pushed to the Queue for next run.

Here is an example of a scheduled script that doing mass updating in the system.

for ( var i in results){
	//DATA PROCESSING		
//check the time unit usage, if less than 100, push to queue
if (nlapiGetContext().getRemainingUsage() <= 100) {
var schStatus = nlapiScheduleScript(nlapiGetContext().getScriptId(), nlapiGetContext().getDeploymentId());
		nlapiLogExecution('debug', 'upush to queued', '------');
		if (schStatus == 'QUEUED') {
			break;
		}
}
}

 

When the time unit usage hits the limitation( less than 100 time unit), the loop will break and the script will be pushed to queue for next run. The NetSuite System will schedule another run later to continue the data processing.