【问题标题】:Script error when Transform PO to Item Receipt Error将 PO 转换为 Item Receipt 错误时的脚本错误
【发布时间】:2022-01-14 02:45:12
【问题描述】:

我是 suitescript 的新手,我有一个计划脚本可以将 PO 转换为 Item Receipt。需要在inventorydetail子记录的Subrecord上创建记录,我得到“USER_ERROR”,“message”:“总库存明细数量必须为1。” - 不知道我做错了什么。如果我对非库存使用相同的代码并删除子记录插入行并对其进行编码

   var csvPOId = 73586;
        var csvPOLocationId = 1;
        var csvPOQty = 1;
        var csvBinId = '';
        var csvSerialLot = '';
        var csvInvQty = 1;
        //

        try {
            var itemReceiptRec = record.transform({
                fromType: record.Type.PURCHASE_ORDER,
                fromId: csvPOId,
                toType: record.Type.ITEM_RECEIPT,
                isDynamic: false
            });
        } catch (e) {
            log.error({
                title: e.name,
                details: e.message
            });
        }


        // Get count - Sublist Lines
        var count = itemReceiptRec.getLineCount({
            sublistId: 'item'
        });

        for (var i=0; i < count; i++) {

            // Item Sub List - Mark as Received
            var itemReceived = itemReceiptRec.getSublistValue({
                sublistId: 'item',
                fieldId: 'itemreceive',
                line: i
            });

            // Location
            itemReceiptRec.setSublistValue({
                sublistId: 'item',
                fieldId: 'location',
                value: csvPOLocationId, // '11 - Central Main Warehouse',
                line: i
            });
            // Quantity

            itemReceiptRec.setSublistValue({
                sublistId: 'item',
                fieldId: 'quantity',
                value: csvPOQty,
                line: i
            });

            // Inventory Detail Sub Record [inventorydetail]

            var subrec = itemReceiptRec.getSublistSubrecord({
                sublistId: 'item',
                line: i,
                fieldId: 'inventorydetail'
            });
            subrec.insertLine({
                sublistId: 'inventoryassignment',
                line: 0
            });
            // // Quantity - Mandatory
            subrec.setSublistValue({
                sublistId: 'inventoryassignment',
                fieldId: 'quantity',
                line: 0,
                value: csvInvQty
            });
        var itemRecID = itemReceiptRec.save({
            enableSourceing: true
        });

        log.debug({
            title: 'New Item Receipt Record',
            details: 'Internal ID ' + itemRecID
        });

【问题讨论】:

  • 在复制和粘贴逻辑时,我为 For 语句删除了 }。 } 就在 itemReceiptRec.save 函数之前。
  • 仅供参考 - 我正在尝试从采购订单中接收 3 个库存项目行,数量均为 1

标签: javascript transform netsuite suitescript receipt


【解决方案1】:

我猜问题在于您设置值的方式。

遵循此逻辑(未包含子记录逻辑)-

for(var j=0; j<count; j++) {

   itemReceiptRec.selectLine({
      sublistId: 'item',
      line: j
   )};

   var itemReceived = itemReceiptRec.getCurrentSublistValue({
                sublistId: 'item',
                fieldId: 'itemreceive',
                line: j
   });

   // Location
   itemReceiptRec.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'location',
        value: csvPOLocationId, // '11 - Central Main Warehouse',
   });

   // Quantity
   itemReceiptRec.setSublistValue({
        sublistId: 'item',
        fieldId: 'quantity',
        value: csvPOQty,
   });

   //Similarly add subrecord code logic
   //Notice I haven't used 'line' while setting sublist value
 
   itemReceiptRec.commitLine({
      sublistId: 'item'
   });
}

itemReceiptRec.save(); 

还将“isDynamic”从 false 更改为 true。

var itemReceiptRec = record.transform({
                fromType: record.Type.PURCHASE_ORDER,
                fromId: csvPOId,
                toType: record.Type.ITEM_RECEIPT,
                isDynamic: true
});

如果有任何关于 cmets 的问题,请告诉我

【讨论】:

  • 嗨,我试过 isDynamic: true ,它给了我一个错误。您还建议了 itemReceiptRec.setCurrentSublistValue,但这不是客户端脚本,它是在服务器上运行的预定脚本。
  • @Renzo setCurrentSublistValue 适用于服务器端脚本。我自己在 Map Reduce 和 UserEvents 中使用过它。试一试!可能会为您提供一些突破
  • 感谢您的提示,我是新手,总是感谢您的建议和提示。
【解决方案2】:

您没有设置其他内容,例如 binnumberissueinventorynumber。除非您收到的物品需要放入垃圾箱或有入库序列号或批号,否则您可能不需要对 inventoryassignment 子列表执行任何操作。

【讨论】:

  • 谢谢,有道理,我会尝试删除 subRecord 逻辑
  • 感谢您的建议,通过删除 subRecord 的逻辑,它奏效了。
  • @Renzo 如果此答案对您有用,那么您需要将其标记为正确答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 2015-08-02
  • 2022-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多