NetSuite 开发日记 —— 库存详细信息记录更改数量问题

2023/12/26 14:03:06

本文主要是介绍NetSuite 开发日记 —— 库存详细信息记录更改数量问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

详细报错:

"type":"error.SuiteScriptError","name":"USER_ERROR","message":"在更改数量之后,您仍需要重新配置库存详细信息记录。"

"type":"error.SuiteScriptError","name":"USER_ERROR","message":"You still need to reconfigure the inventory detail record after changing the quantity."

原因:

SuiteAnswers ID 81448 的解答:
当系统启用了库存状态功能,访问子记录时会发生已添加行的行为,对新创建的库存详细信息子记录的子列表使用 selectNewLine 方法会返回错误“在更改数量之后,您仍需要重新配置库存详细信息记录” 。如果遇到此问题,建议使用 selectline 方法。

解决方案

var rec = record.transform({
  fromType: 'workorder',
  fromId: wordOrderId,
  toType: 'workordercompletion',
  isDynamic: true,
  defaultValues: {
    isbackflush: 'T'
  }
});

// 正文字段赋值
rec.setValue('trandate', new Date());
/** 其他正文字段赋值 **/

// 行字段赋值
var sublistId = 'component';
var lineCounts = rec.getLineCount(sublistId);
for (var i = 0; i < lineCounts; i++) {
  rec.selectLine({
    sublistId: sublistId,
    line: i
  });
  rec.setCurrentSublistValue({
    sublistId: sublistId,
    fieldId: 'quantity',
    value: lineData[i].qty,
  });
  var subRec = rec.getCurrentSublistSubrecord({
    sublistId: sublistId,
    fieldId: 'componentinventorydetail',
  });
  var detailData = lineData[i].details;
  var detailSublistId = 'inventoryassignment';
  for (var j = 0; j < detailData.length; j++) {
	// 根据SuiteAnswers的解答,因为启用了库存状态功能,此处需要使用selectLine方法,并非selectNewLine方法
    // subRec.selectNewLine({sublistId: detailSublistId});
    subRec.selectLine({sublistId: detailSublistId,line:j});
    subRec.setCurrentSublistText({
      sublistId: detailSublistId,
      fieldId: 'issueinventorynumber',
      text: detailData[j].invNum,
    });
    subRec.setCurrentSublistValue({
      sublistId: detailSublistId,
      fieldId: 'binnumber',
      value: detailData[j].binNum,
    });
    subRec.setCurrentSublistValue({
      sublistId: detailSublistId,
      fieldId: 'inventorystatus',
      value: detailData[j].status,
    });
    subRec.setCurrentSublistValue({
      sublistId: detailSublistId,
      fieldId: 'quantity',
      value: detailData[j].quantity,
    });
    subRec.commitLine({
      sublistId: detailSublistId
    });
  }
  rec.commitLine({
    sublistId: sublistId
  });
}

rec.save();

另外,根据实际测试,使用标准模式创建完工单也可以避免该报错。

var rec = record.transform({
  fromType: 'workorder',
  fromId: wordOrderId,
  toType: 'workordercompletion',
  isDynamic: false,
  defaultValues: {
    isbackflush: 'T'
  }
});

// 正文字段赋值
rec.setValue('trandate', new Date());
/** 其他正文字段赋值 **/

// 行字段赋值
var sublistId = 'component';
var lineCounts = rec.getLineCount(sublistId);
for (var i = 0; i < lineCounts; i++) {
  rec.setSublistValue({
    sublistId: sublistId,
    fieldId: 'quantity',
    value: lineData[i].qty,
    line: i
  });
  var subRec = rec.getSublistSubrecord({
    sublistId: sublistId,
    fieldId: 'componentinventorydetail',
    line: i
  });
  var detailData = lineData[i].details;
  var detailSublistId = 'inventoryassignment';
  for (var j = 0; j < detailData.length; j++) {
	// 标准模式下,给issueinventorynumber赋值时,建议使用setSublistValue方法,而非setSublistText方法
   // 原因:当系统中存在不同物料但库存编码相同时,此处可能发生USER_ERROR的错误,此类错误较难排查
    subRec.setSublistValue({
      sublistId: detailSublistId,
      fieldId: 'issueinventorynumber',
      value: detailData[j].invNumId,
	  line: j
    });
    subRec.setSublistValue({
      sublistId: detailSublistId,
      fieldId: 'binnumber',
      value: detailData[j].binNum,
	  line: j
    });
    subRec.setSublistValue({
      sublistId: detailSublistId,
      fieldId: 'inventorystatus',
      value: detailData[j].status,
	  line: j
    });
    subRec.setSublistValue({
      sublistId: detailSublistId,
      fieldId: 'quantity',
      value: detailData[j].quantity,
	  line: j
    });
  }
}

rec.save();

其他参考答案:

  • Resolve Error: "You still need to reconfigure the inventory detail record after changing the quantity."
  • Unable to set Inventory Detail on Item Fulfillment Record - Suitescript 2
  • Netsuite reconfigure inventory detail error


这篇关于NetSuite 开发日记 —— 库存详细信息记录更改数量问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程