AfterSubmit 和设置字段值

AfterSubmit and setting field value

我正在尝试在提交记录后更新字段,但该字段没有更新。我知道脚本正在触发,因为调试显示的是旧重量值。您不能更新 AfterSubmit 用户事件中的字段吗?

// 2.0 - Fluent
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(["N/record"], function (r) {
    function onAfterSubmit(context) {
        var  oldweight = context.newRecord.getValue({ fieldId: 'custbody93' });

            log.debug({
            title: 'Old Weight',
            details: oldweight
            });

        if (oldweight) {
            var fixWeight = context.newRecord;
            context.newRecord.setValue('custbody103', 'oldweight');
        };
    }  
   return {
        afterSubmit: onAfterSubmit
    };
});

afterSubmit事件中,记录已经提交并存储在数据库中,因此您不能直接在内存中的记录上更新字段。

您需要使用 N/recordload()save() 记录或使用 submitFields() 才能正确更新数据库。

更改触发用户事件的同一记录上的字段的最佳做法是改用 beforeSubmit;在该入口点内,您当前的代码将按预期工作。

我在 understanding User Events and one on how to work with records on my YouTube channel 上有一个视频系列。