You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NetSuite库存转移Inventory Assignment报INVALID_FLD_VALUE错误求助

NetSuite库存转移脚本:binnumber字段INVALID_FLD_VALUE错误解决

问题背景

从仓位地点向非仓位地点执行库存转移时,脚本创建Inventory Detail环节持续触发INVALID_FLD_VALUE错误,提示:

"You have entered an Invalid Field Value 1449 for the following field: binnumber"

手动转移该仓位编号操作正常,但脚本执行始终报错,binnumber为选择类型,已尝试设置isDynamic=true等方案无效。

原问题代码

var inventoryTransfer = RECORDMODULE.create({
            type: RECORDMODULE.Type.INVENTORY_TRANSFER,
            isDynamic: true,
            defaultValues: null
        });

        inventoryTransfer.setValue({
            fieldId: "location",
            value: fromlocation,
        });
        inventoryTransfer.setValue({
            fieldId: "transferlocation",
            value: tolocation,
        });
        inventoryTransfer.setValue({
            fieldId: "trandate",
            value: new Date(),
        });
        inventoryTransfer.setValue({
            fieldId: "memo",
            value: 'test IT'
        });
        inventoryTransfer.setValue({
            fieldId: "custbody6",
            value: presta_order_id
        });

        // Loop through each item and add it to the inventory transfer
        processItems.forEach(function (item, key) {
            log.debug('item', item);
            if (item.id) {

                inventoryTransfer.selectNewLine({
                    sublistId: "inventory",
                });
                inventoryTransfer.setCurrentSublistValue({
                    sublistId: "inventory",
                    fieldId: "item",
                    value: item.id
                });
                inventoryTransfer.setCurrentSublistValue({
                    sublistId: "inventory",
                    fieldId: "adjustqtyby",
                    value: item.quantity
                });
                inventoryTransfer.setCurrentSublistValue({
                    sublistId: "inventory",
                    fieldId: "quantityonhand",
                    value: itemDetails.data[0].values.quantityonhand
                });
                // Create inventory detail (assignments)
                var inventoryDetail = RECORDMODULE.create({
                    type: RECORDMODULE.Type.INVENTORY_DETAIL,
                });
                var lineCount = inventoryDetail.getLineCount({ sublistId: 'inventoryassignment' });

                log.debug('line count', lineCount);

                inventoryDetail.insertLine({
                    sublistId: 'inventoryassignment',
                    line: 0
                });

                inventoryDetail.setSublistValue({
                    sublistId: 'inventoryassignment',
                    fieldId: 'binnumber',
                    value: binId, // Replace with actual bin internal ID
                    line: 0
                });

                inventoryDetail.setSublistValue({
                    sublistId: 'inventoryassignment',
                    fieldId: 'quantityavailable',
                    value: itemDetails.data[0].values.quantityonhand, // Ensure this matches the transferred quantity
                    line: 0
                });
                inventoryDetail.setSublistValue({
                    sublistId: 'inventoryassignment',
                    fieldId: 'quantity',
                    value: item.quantity, // Ensure this matches the transferred quantity
                    line: 0
                });

                log.debug('inventoryDetail',inventoryDetail);
                // // Commit the inventory assignment line
                inventoryDetail.save({
                    sublistId: 'inventoryassignment'
                });
            }
        });
        // Commit the line for the item
        inventoryTransfer.commitLine({
            sublistId: 'inventory'
        });

问题根源

原代码错误地独立创建了Inventory Detail记录,而非通过库存转移子列表的inventorydetail子记录关联操作。Inventory Detail是库存转移子列表行的附属记录,必须在主记录的子列表上下文内操作,不能单独创建后保存。

解决方案

修正后的核心逻辑

  1. 在库存子列表行中启用inventorydetailreq字段,触发库存明细编辑
  2. 通过getCurrentSublistSubrecord获取关联的Inventory Detail子记录
  3. 在子记录上下文中设置仓位分配信息
  4. 随主库存转移记录一起提交保存

修正后的代码片段

// Loop through each item and add it to the inventory transfer
processItems.forEach(function (item, key) {
    log.debug('item', item);
    if (item.id) {
        inventoryTransfer.selectNewLine({
            sublistId: "inventory",
        });
        inventoryTransfer.setCurrentSublistValue({
            sublistId: "inventory",
            fieldId: "item",
            value: item.id
        });
        inventoryTransfer.setCurrentSublistValue({
            sublistId: "inventory",
            fieldId: "adjustqtyby",
            value: item.quantity
        });
        // 启用库存明细需求
        inventoryTransfer.setCurrentSublistValue({
            sublistId: "inventory",
            fieldId: "inventorydetailreq",
            value: true
        });

        // 获取关联的Inventory Detail子记录
        var inventoryDetail = inventoryTransfer.getCurrentSublistSubrecord({
            sublistId: "inventory",
            fieldId: "inventorydetail"
        });

        // 设置仓位分配行
        inventoryDetail.selectNewLine({
            sublistId: "inventoryassignment"
        });
        inventoryDetail.setCurrentSublistValue({
            sublistId: "inventoryassignment",
            fieldId: "binnumber",
            value: binId // 确保此处为仓位的内部ID
        });
        inventoryDetail.setCurrentSublistValue({
            sublistId: "inventoryassignment",
            fieldId: "quantity",
            value: item.quantity
        });
        // 提交仓位分配行
        inventoryDetail.commitLine({
            sublistId: "inventoryassignment"
        });

        // 提交库存子列表行
        inventoryTransfer.commitLine({
            sublistId: "inventory"
        });
    }
});

// 最后保存库存转移主记录
var transferId = inventoryTransfer.save({
    enableSourcing: true,
    ignoreMandatoryFields: false
});

关键注意事项

  • 确认binId的有效性:必须使用仓位的内部ID,而非外部ID、名称或其他标识,可通过日志打印binId值验证正确性
  • 目标地点无需设置仓位:因为目标是非仓位地点,Inventory Detail中仅需指定源仓位即可
  • 无需单独保存Inventory Detail:子记录会随主库存转移记录的save()操作一同保存,原代码中的inventoryDetail.save()是错误操作
  • 动态模式下的上下文依赖:必须先设置inventorydetailreq=true,才能成功获取到Inventory Detail子记录的操作上下文

内容的提问来源于stack exchange,提问作者Hazree Mahmood

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 01:23:14