SuiteScript 2.0 Map减少脚本完成示例

时间:2018-02-13 08:20:52

标签: mapreduce scriptlet

我在Netsuite中遇到了SSS USAGE LIMIT EXCEEDED错误。 我打算将搜索更改为使用Map Reduce Script,但是,我没有找到任何完整的示例来调用Map Reduce Script,比如如何将参数传递给Map Reduce Script并从中获取结果集。你能告诉我怎么样吗?提前致谢

下面显示了如何定义调用Map Reduce Script的任务 SuiteScript 2.0 UserEvent Script to Call Map Reduce

define(['N/record', 'N/log', 'N/Task'],
function (record, log, task) {
    function setFieldInRecord (scriptContext) {
        log.debug({
            'title': 'TESTING',
            'details': 'WE ARE IN THE FUNCTION!'
        });
        if (scriptContext.type === scriptContext.UserEventType.EDIT) {
            var scriptTask = task.create({
                taskType: task.TaskType.MAP_REDUCE
            });
            scriptTask.scriptId = 'customscript_id';
            scriptTask.deploymentId = 'customdeploy_id';
            var scriptTaskId = scriptTask.submit();
            //How to pass parameter to getInputData?
            //How to get the result?

        }
    }
    return {
        beforeSubmit: setFieldInRecord
    };
}

);

1 个答案:

答案 0 :(得分:1)

Map / Reduce脚本类型为您提供了4个入口点函数来加载/处理您的数据:

  • getInputData(inputContext)
  • 地图(mapContext)
  • 减少(reduceContext)
  • 总结(summaryContext)

    示例:

    function summarize(context) { context.output.iterator().each(function(key, value) { // your logic here return true; }); }

看看这个帮助中心部分,有一些示例(仅适用于NetSuite帐户): https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4387799161.html