Netsuite 脚本 beforeLoad 记录未被修改

Pat*_*ane 2 javascript oracle netsuite suitescript

我试图在用户打开采购订单时修改它。这似乎是一个非常简单的例子,但似乎不起作用。在 GUI 中我没有看到“测试”备忘录。在脚本调试中,备注字段为空。

由于调试,我知道脚本正在运行。

/**
 * Update Drop Ship PO with route Information
 *
 * @author Patrick 
 * @NApiVersion 2.0
 * @NScriptType UserEventScript
 */


define(['N/search', 'N/record'],

    function(search, record) {
        function beforeLoad(context) {
            var newRecord = context.newRecord;
            newRecord.setValue({fieldId: 'memo', value: 'this is a test'});
            log.debug({title: 'memo', details: newRecord.getValue({fieldId: 'memo'})});

            return true;
        }
      return {
        beforeLoad: beforeLoad
    };
});
Run Code Online (Sandbox Code Playgroud)

我假设它与我可以修改的记录有关,但我一生都无法在文档中找到有效的示例。任何帮助将不胜感激。

eri*_*ugh 5

您无法修改 中现有记录的字段beforeLoad;有关详细信息,请参阅帮助页面beforeLoad。这是限制的一个片段beforeLoad

  • 当您加载/访问在线表单时,无法触发 beforeLoad 用户事件。
  • 无法操作在 beforeLoad 脚本中加载的记录的数据。如果您尝试更新 beforeLoad 中加载的记录,则该逻辑将被忽略。
  • 可以对 beforeLoad 用户事件中创建的记录进行数据操作。
  • 将子自定义记录附加到其父记录或将子自定义记录与其父记录分离会触发编辑事件。

第二个要点与您的问题相关。


小智 5

newRecord.setValue在 beforeLoad 中不起作用。newRecord.submitFields如果你像下面这样使用那就更好了

record.submitFields({
    id: newRecord.id,
    type: newRecord.type,
    values: {'memo': 'this is a test'}
});
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你!!