【问题标题】:Replace existing sublist subrecords in NetSuite SuiteScript 2.0替换 NetSuite SuiteScript 2.0 中的现有子列表子记录
【发布时间】:2017-06-16 18:12:51
【问题描述】:

我已经为此苦苦挣扎了一段时间。这可能是 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();
}

如cmets所示,报错:"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:请输入以下值:序列号/批号、Bin、数量

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

感谢您提供任何帮助或其他尝试的想法。我也尝试过重新使用现有行(而不是插入新行),但没有运气。

【问题讨论】:

    标签: netsuite suitescript suitecloud


    【解决方案1】:

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

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

    【讨论】:

    • 嘿@Charl 远射,但这是我能想到的唯一联系方式。你知道你过去是如何解决这个问题的吗?这是唯一的在线帖子! “无法找到具有键的子列表项的匹配行:[orderLine] 和值:[1]”quabr.com/47307152/…
    • @WilliamW 我花了一段时间才意识到这是我的旧帖子之一,哈哈。我已取消删除问题。请在那里评论你是如何尝试这样做的。您是通过用户事件脚本还是客户端脚本执行此操作?评论我的帖子,我会尽我所能回答:stackoverflow.com/questions/47307152/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多