什么是在SS2.0中传递变量的"官方"方式?

fel*_*ang 1 netsuite suitescript

遇到一种愚蠢的问题.

我想在map/reduce脚本的阶段之间传递变量.是否存在"官方"或最佳方式(而不是使用返回的结果发送).

这是我的最后一种方法:

    /**
    * @NApiVersion 2.0
    * @NScriptType MapReduceScript
    */

    define(["N/search", "N/record", "N/email", "N/runtime", "N/task", "/SuiteScripts/Libraries/tools_lib"],
    function (search, record, email, runtime, task, tools) {

    var ss = runtime.getCurrentSession();
    var conf = {};

    /**
     * Retrieve the CSV contents and return as an object
     * @return {Array|*}
     */
    function getInputData() {

        log.debug("setting", "foo");
        ss.set({name: "foo", value: "bar"});

        //Session
        var foo = ss.get({name: "foo"});
        log.debug("foo 1", foo);

        //var pass
        conf["foo"] = "bar";

        return [1, 2, 3];
    }

    /**
     * Search and group by type, all records with matching entries on the CSV field
     * @param context
     * @return {boolean}
     */
    function map(context) {

        //Session
        var foo = ss.get({name: "foo"});
        log.debug("foo 2", foo);

        //Var pass
        log.debug("foo 3", conf["foo"]);

        return false;
    }
Run Code Online (Sandbox Code Playgroud)

foo 1 =吧

foo2 = null

foo3 = null

eri*_*ugh 5

NetSuite存储return上一阶段的任何内容context.value.

无论您返回什么数据类型,它都将始终作为a发送到下一阶段String,因此JSON.parse如果您想使用不同的数据类型,则需要它.

function getInputData() {
  return [1,2,3];
}

function map(context) {
  log.debug(JSON.parse(context.value));
}
Run Code Online (Sandbox Code Playgroud)

您无法访问前一阶段的特定变量.如果要传递数据,则需要使用要传递的值构建适当的数据结构return,然后context.value在后续阶段将其解析出来.