SuiteScriptError INVALID_FLD_VALUE 值 -1.0 超出字段 adjustqtyby 的有效 min/max 范围

SuiteScriptError INVALID_FLD_VALUE Value -1.0 outside of valid min/max range for field adjustqtyby

正在尝试创建库存调整以使该位置的所有可用项目归零。在 adjustqty 字段中设置负值时,它表示字段值无效。 错误信息 "type":"error.SuiteScriptError","name":"INVALID_FLD_VALUE","message":"Value -1.0 超出字段 adjustqtyby 的有效 min/max 范围

代码

let createInventoryAdjustment = (siteId)=> {
            try {
                var inventoryAdjustmentRecord = record.create({
                    type: record.Type.INVENTORY_TRANSFER,
                    isDynamic: true
                });
                inventoryAdjustmentRecord.setValue("account",accountId)
                let index = 0;
                let currentInventoryData = getSerielNumbers(siteId);
                let itemVsSerialNo = currentInventoryData.results;
                let itemsVsQty = currentInventoryData.itemsVsQty;
                for (var key in itemVsSerialNo) {
                    log.debug("itemVsSerialNo[key]",itemVsSerialNo[key]);

                    var inveRec = inventoryAdjustmentRecord.selectNewLine({
                        sublistId : 'inventory'
                    });
                    inventoryAdjustmentRecord.setCurrentSublistValue({
                        fieldId: "item",
                        value: key,
                        line: index,
                        sublistId: 'inventory'
                    });
                    inventoryAdjustmentRecord.setCurrentSublistValue({
                        fieldId: "location",
                        value: siteId,
                        line: index,
                        sublistId: 'inventory'
                    });
                    log.debug(itemsVsQty[key],itemVsSerialNo[key]);

                    inventoryAdjustmentRecord.setCurrentSublistValue({
                        fieldId: "adjustqtyby",
                        value:  parseInt(itemsVsQty[key]*-1),
                        line: index,
                        sublistId: 'inventory'
                    });
                    if(itemVsSerialNo[key][0].type!="inventoryitem") {
                        let inventoryDetail = inventoryAdjustmentRecord.getCurrentSublistSubrecord({
                            sublistId: 'inventory',
                            fieldId: 'inventorydetail',
                            line: index
                        });
                        for (let i=0;i<itemVsSerialNo[key].length;i++) {
                         let inventoryAssignment =  inventoryDetail.selectNewLine({
                                sublistId : 'inventoryassignment'
                            });

                            inventoryAssignment.setCurrentSublistValue({
                                sublistId: 'inventoryassignment',
                                fieldId: 'quantity',
                                value: (itemVsSerialNo[key][i].qtyOnhand*-1),
                                line: i
                            });
                            inventoryAssignment.setCurrentSublistValue({
                                sublistId: 'inventoryassignment',
                                fieldId: 'issueinventorynumber',
                                value: itemVsSerialNo[key][i].inventoryNoId,
                                line: i
                            });
                            inventoryAssignment.commitLine({
                                sublistId : 'inventoryassignment'
                            });
                        }
                    }
                    index++;


                    inventoryAdjustmentRecord.commitLine({
                        sublistId : 'inventory'
                    });

                    log.debug("key",key);
                    //break;
                }
                if (index == 0) {
                    // NO items to reverse
                    return {
                        isCreated: true,
                        tranId: null,
                    };
                }
                let tranId = inventoryAdjustmentRecord.save({ignoreMandatoryFields: true});
                log.debug("inventoryAdjustmentRecord",tranId);
                return {
                    isCreated: true,
                    tranId: tranId
                };
            } catch (err) {
                log.debug('error@inventoryAdjustment', err);
                return {
                    isCreated: false,
                    error: 'Unable to create Return Inventory Transfer'
                }
            }
        }

您正在创建不能转移负数量的库存转移,而不是:

var inventoryAdjustmentRecord = record.create({
    type: record.Type.INVENTORY_TRANSFER,
    isDynamic: true
});

你应该有:

var inventoryAdjustmentRecord = record.create({
    type: record.Type.INVENTORY_ADJUSTMENT,
    isDynamic: true
});