提交后如何检查订单项是否有任何变化?

How to check if there is any changes in line items on after submit?

我有宝。 我想检查提交后项目行是否已更改

 function onAction(context) {
        var newRec = context.newRecord;
        var oldRec = context.oldRecord;


        var newCount = newRec.getLineCount({
            sublistId: 'item'
        });

        var oldCount = oldRec.getLineCount({
            sublistId: 'item'
        });

        if (newCount != oldCount) {
            log.debug('result', 'true')
        } else {
            log.debug('result', 'false')
        }


    }

    return {
        onAction: onAction
    }

我是用计数线做的,但我还想检查该行是否有任何变化,而不仅仅是行数

您需要在每一行中比较您关心的每个字段。这是一个示例函数,如果通过比较行计数更改了任何行,则 returns true/false 然后是每行的项目、数量和费率。您可以修改它以满足您的需要。

这样使用some(),第一行第一个不同的字段将停止比较,return true.

function linesChanged(context) {
    const fields = ['item', 'quantity', 'rate'];

    const oldRecord = context.oldRecord;
    const newRecord = context.newRecord;
    const oldLineCount = oldRecord.getLineCount({ sublistId: 'item' });
    const newLineCount = newRecord.getLineCount({ sublistId: 'item' });

    if (oldLineCount !== newLineCount) {
        return true;
    }

    for (let i = 0; i < newLineCount; i++) {
        var lineChanged = fields.some(field => {
            const oldValue = oldRecord.getSublistValue({ sublistId: 'item', fieldId: field, line: i });
            const newValue = newRecord.getSublistValue({ sublistId: 'item', fieldId: field, line: i });

            return oldValue !== newValue;
        });

        if (lineChanged) {
            return true;
        }
    }

    return false;
}