SuiteScript 2.0 UserEvent脚本以调用Map Reduce [英] SuiteScript 2.0 UserEvent Script to Call Map Reduce

查看:151
本文介绍了SuiteScript 2.0 UserEvent脚本以调用Map Reduce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好.

我正在尝试获取一个User Event脚本来调用或使用Map Reduce脚本.我对Map Reduce脚本的概念真的很陌生,没有足够的运气来寻找资源.本质上,我想做的是调用Map Reduce脚本,该脚本查找具有相同项目名称"的未清交易,并将该项目上的类别"设置为用户设置的新项目. Map Reduce脚本需要使用当前记录中的项目名称"和类".

I am trying to get a User Event script to call or use a Map Reduce script. I am really new to the concept of a Map Reduce script and am not having much luck finding resources. Essentially, what I want to do is call a Map Reduce script that finds open transactions with the same Item Name and sets the Class on that item to the new item set by the User. The Map Reduce script would need to the Item Name and Class from the current record.

这是我的用户事件:

/**
* @NApiVersion 2.0
* @NScriptType UserEventScript
*/

define(['N/record', 'N/log'],
    function (record, log) {
        function setFieldInRecord (scriptContext) {
            log.debug({
                'title': 'TESTING',
                'details': 'WE ARE IN THE FUNCTION!'
            });
            if (scriptContext.type === scriptContext.UserEventType.EDIT) {
                var old_Record = scriptContext.oldRecord;
                var cur_Record = scriptContext.newRecord;
                var oldClassId = old_Record.getValue({ fieldId: 'class'});
                var curClassId = cur_Record.getValue({ fieldId: 'class'});
                if ( oldClassId != curClassId ) {
                    // CALL MAP REDUCE HERE
                }
            }
        }
        return {
            beforeSubmit: setFieldInRecord
        };
    }
);

Map Reduce脚本是一个单独的文件,还是嵌入在用户事件脚本中?我想如果我知道如何从User Event中调用它,我可以使Map Reduce起作用.感谢您对此问题的投入.谢谢!

Is the Map Reduce Script a separate file or is it embedded in the User Event script? I think I can get the Map Reduce to work if I know how to call it from the User Event. I appreciate any input with this question. Thank you!

推荐答案

这是我们处理这种情况的方式.

Here is how we handled this situation.

我们确保在上面的User Event代码中将'N/task'添加到define语句中.然后,在满足条件的用户事件中,为了调用Map/Reduce脚本,我们执行了以下操作:

We made sure to add 'N/task' to the define statement in the above code for the User Event. Then, in the User Event when the conditions were met in order to call the Map / Reduce Script, we did this:

var scriptTask = task.create({
     taskType: task.TaskType.MAP_REDUCE
});
scriptTask.scriptId = 'customscript_id';
scriptTask.deploymentId = 'customdeploy_id';
var scriptTaskId = scriptTask.submit();

这成功地从用户事件中调用了Map Reduce脚本.

This successfully called the Map Reduce Script from the User Event.

我希望这对以后的工作有所帮助.

I hope this helps out someone in the future.

谢谢.

这篇关于SuiteScript 2.0 UserEvent脚本以调用Map Reduce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆