1

我一直在努力解决这个问题。这可能是 NetSuite 中的一个错误,但我认为在接受这个想法之前我会咨询 SuiteScript ninjas。

以下是场景:我有一个销售订单,其中包含批次编号库存项目的行,其中预先填写了批次信息的库存详细信息:与库存明细相符的订单 以下是该库存详细信息的内容:在此处输入图像描述

我正在尝试编写该销售订单的履行脚本,但我需要在履行时更改库存详细信息。这工作正常并且在 NetSuite UI 中是允许的,但我无法让 SuiteScript Restlet 做同样的事情。下面是 Restlet 中的相同代码:

function runFullfillmentTest() {
  var fulfillment = record.transform({
    fromType: 'salesorder',
    fromId: 21424,
    toType: 'itemfulfillment'
  });

  var fulfillmentLineCount = fulfillment.getLineCount({
    sublistId: 'item'
  });

  for (var i = 0; i < fulfillmentLineCount; i++) {
    fulfillment.setSublistValue({
      sublistId: 'item',
      line: i,
      fieldId: 'itemreceive',
      value: false
    });
  }

  // Orderline 3 has the following inventory details pre-set
  // Line |   Lot Number  |   Quantity
  // 0    |   L0001       |   2
  // 1    |   L0002       |   1
  // 2    |   L0003       |   1

  var fulfillmentLineForItem = fulfillment.findSublistLineWithValue({
    sublistId: 'item',
    fieldId: 'orderline',
    value: '3'
  });

  fulfillment.setSublistValue({
    sublistId: 'item',
    line: fulfillmentLineForItem,
    fieldId: 'itemreceive',
    value: true
  });

  fulfillment.setSublistValue({
    sublistId: 'item',
    line: fulfillmentLineForItem,
    fieldId: 'quantity',
    value: '5'
  });

  var inventorydetailForFulfillmentLine = fulfillment.getSublistSubrecord({
    sublistId: 'item',
    fieldId: 'inventorydetail',
    line: fulfillmentLineForItem
  });

  inventorydetailForFulfillmentLine.setValue({
    fieldId: 'quantity',
    value: '5'
  });

  var existingLineCount = inventorydetailForFulfillmentLine.getLineCount({
    sublistId: 'inventoryassignment'
  });

  for (var i = 0; i < existingLineCount; i++) {
    inventorydetailForFulfillmentLine.removeLine({
      sublistId: 'inventoryassignment',
      line: 0
    });
  }

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

  inventorydetailForFulfillmentLine.setSublistValue({
    sublistId: 'inventoryassignment',
    line: 0,
    fieldId: 'issueinventorynumber',
    value: '154' // L0003
  });

  // Interestingly enough, if you take out the line below, you'll 
  // get the error: "USER_ERROR : Please enter value(s) for: Serial/Lot Number, Bin, Quantity"
  // So its almost like issueinventorynumber and quantity aren't being seen as
  // being set by NetSuite
  // I think it does see binnumber, but thinks it is invalid because it 
  // believes the issueinventorynumber to be is blank
  inventorydetailForFulfillmentLine.setSublistValue({
    sublistId: 'inventoryassignment',
    line: 0,
    fieldId: 'binnumber',
    value: '111' // W.3.0.0
  });

  inventorydetailForFulfillmentLine.setSublistValue({
    sublistId: 'inventoryassignment',
    line: 0,
    fieldId: 'quantity',
    value: '5'
  });


  // This will throw error:
  // "INVALID_FLD_VALUE : You have entered an Invalid Field Value 111 for the following field: binnumber"
  return fulfillment.save();
}

如评论中所示,我收到错误:"INVALID_FLD_VALUE : You have entered an Invalid Field Value 111 for the following field: binnumber"

在这种情况下111是 bin W.3.0.0 的有效 internalid

有趣的是,如果删除将 binnumber 设置为的行,111则会收到错误消息:

USER_ERROR:请输入以下值:序列号/批号、Bin、数量

看起来我错过了批次和数量字段,但我只是设置了这些?我认为它抱怨111无效,因为它认为批号尚未设置,并且需要它来验证 binnumber。

任何帮助或其他尝试的想法表示赞赏。我也尝试过重新使用现有的行(而不是插入新的行),但没有运气。

4

1 回答 1

0

在保存 Item Fulfillment 之前尝试保存库存详细信息对象。请记住,您使用的是“getSublistSubrecord”,它会加载一条记录。因此,在对此进行更改后,您需要保存记录:

inventorydetailForFulfillmentLine.save();
return fulfillment.save();
于 2020-03-05T08:41:22.750 回答