NetSuite 客户端脚本字段使用旧项目值更改

NetSuite Client Script fieldChanged using old item values

我按照以下逻辑制作了一个简单的客户端脚本:一旦添加了新项目或将项目更改为新项目,毛利率将自动计算并添加到该项目的相应字段。我遇到的问题是 fieldChanged 给我该项目的旧(或未定义)子列表值,就好像它还没有改变一样。有没有办法告诉 NetSuite 在更改项目后等待其相应的子列表值更新,然后再使用 fieldChanged 填充值?谢谢!

function fieldChanged(context) {
    var currentRecord = context.currentRecord;
    var sublistName = context.sublistId;
    var sublistFieldName = context.fieldId;
    var line = context.line;

    if (sublistName === 'item' && sublistFieldName === 'item'){
        var costrateestimate = currentRecord.getCurrentSublistValue({sublistId: sublistName,fieldId: 'costestimaterate'});
        var amount = currentRecord.getCurrentSublistValue({sublistId: sublistName,fieldId: 'amount'});
        var quantity = currentRecord.getCurrentSublistValue({sublistId: sublistName,fieldId: 'quantity'});
        var grossPerc = Math.round((1-(costrateestimate/amount*quantity))*100);

        log.debug("Gross Margin Calculated = 100 - ("+costrateestimate+" / "+amount+" * "+currentRecord.getCurrentSublistValue({sublistId: sublistName,fieldId: 'quantity'})+") = "+grossPerc+"%");

        currentRecord.setCurrentSublistValue({
            sublistId: sublistName,
            fieldId: 'custcol_gross_margin_perc',
            value: grossPerc
        });
    }
}

想通了!我需要使用 postSourcing 入口点而不是 fieldChanged...