In SuiteScript 1.0, use nlobjContext.getRemainingUsage() to retrieve the remaining units. An nlobjContext reference is retrieved using the global nlapiGetContext function.
// 1.0
var context = nlapiGetContext();
nlapiLogExecution("DEBUG", "Governance Monitoring", "Remaining Usage = " + context.getRemainingUsage());
nlapiSearchRecord("transaction"); // uses 10 units
nlapiLogExecution("DEBUG", "Governance Monitoring", "Remaining Usage = " + context.getRemainingUsage());
In SuiteScript 2.0, use the getRemainingUsage method of the N/runtime module's Script object.
// 2.0
require(["N/log", "N/runtime", "N/search"], function (log, runtime, s) {
var script = runtime.getCurrentScript();
log.debug({
"title": "Governance Monitoring",
"details": "Remaining Usage = " + script.getRemainingUsage()
});
s.load({"id":"customsearch_mysearch"}); // uses 5 units
log.debug({
"title": "Governance Monitoring",
"details": "Remaining Usage = " + script.getRemainingUsage()
});
});