替换NetSuite SuiteScript 2.0中的现有子列表子记录

时间:2017-06-16 18:12:51

标签: netsuite suitescript suitecloud

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

以下是该方案: 我有一个销售订单,其中包含批次库存项目的行,其中包含预先填写了批次信息的库存明细:Order with line with inventory detail 以下是该广告资源详细信息的内容:enter image description here

我正在尝试编写该销售订单的履行,但我需要在履行时更改库存明细。这很好,并且在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

的有效内部ID

有趣的是,如果删除将binnumber设置为111的行,那么我会收到错误:"USER_ERROR : Please enter value(s) for: Serial/Lot Number, Bin, Quantity"

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

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

1 个答案:

答案 0 :(得分:0)

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

inventorydetailForFulfillmentLine.save();
return fulfillment.save();