Netsuite Script beforeLoad 记录未被修改

Netsuite Script beforeLoad record not being modified

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

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

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

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

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

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

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

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

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

希望对您有所帮助!!