NetSuite 批量更新脚本成功运行,但没有任何更新

问题描述 投票:0回答:1

已经担任开发人员多年,但刚刚接触 NetSuite 脚本编写。我想从简单开始,创建一个脚本来更新采购订单上所有项目的 COMMENT 字段。我首先按照here找到的教程开始。

我修改后的脚本如下 - 它应该更新 PO 标头的 MEMO 字段,然后更新每一行的 COMMENT 字段。我按照文章中的步骤保存脚本,创建批量更新,然后运行它。在我的标准中,我设置:“交易编号/ID”和“有关键字 90999”(这样它只会在一个特定的采购订单上运行)。我通过单击“预览”确认我的标准是正确的,它只返回一个 PO。

当我运行批量更新时,它运行良好,并表示已在 1 条记录上成功运行(这很好)。 PO 标头中的 MEMO 字段确实会更新,但每行的 COMMENT 字段不会更新。我做错了什么或者错过了一些简单的事情吗? getLineCount 调用是否不正确?

请注意,我是在沙盒环境中执行所有这些操作,以防产生任何影响

更新: 我知道 getLineCount 调用返回正确的数字,因为如果我将 poRec.setValue 调用移到 for 循环内,它就会运行。那么我的 poRec.setSublistValue 调用一定有问题吗?

/**
*@NApiVersion 2.0
*@NScriptType MassUpdateScript
*/
define(['N/record'],
function (record) {
function each(params) {
    // Need to LOAD each record and SAVE it for changes to take effect
    // LOAD the PO
    var poRec = record.load({
        type: params.type,
        id: params.id
    });

    //var mainDepartment = poRec.getValue('department');
    var mainDepartment = 'Hello World';

    poRec.setValue({
        fieldId: 'memo',
        value: mainDepartment
    });

    // get a count of the line items
    var lineCount = poRec.getLineCount({
        sublistId: 'item'
    });

    // go through each of the line items and set the department to the main level department
    for (var i = 0; i < lineCount; i++) {
        poRec.setSublistValue({
            sublistId: 'item',
            fieldId: 'comment',
            line: i,
            value: mainDepartment
        });
    }

    // SAVE the PO
    poRec.save();
}
return {
    each: each
};
});
netsuite suitescript
1个回答
0
投票

项目子列表上没有“评论”字段。您可能指的字段是“描述”(在搜索中表示为行级“备忘录”字段 - Netsuite 获胜!)

© www.soinside.com 2019 - 2024. All rights reserved.