我剩下多少单位

在 SuiteScript 1.0 中,使用 nlobjContext.getRemainingUsage() 检索剩余单位。使用全局 nlapiGetContext 函数检索 nlobjContext 引用。

// 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());

在 SuiteScript 2.0 中,使用 N/runtime 模块的 Script 对象的 getRemainingUsage 方法。

// 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()
    });
});