在将 netsuite 销售订单转换为履行时,您如何选择要履行的行项目?

时间:2021-07-22 19:34:36

标签: javascript transform netsuite suitescript

尝试使用

转换 NetSuite 销售订单

 var fulfillment = record.transform({
   fromType: record.Type.SALES_ORDER,
   fromId: currentRecord.id,
   toType: record.Type.ITEM_FULFILLMENT,
   isDynamic: true
 });

收到错误“USER_ERROR”,“message”:“您必须为此交易输入至少一个行项目。”

履行包含 7 个行项目,但在fulfillment.save() 之后,它返回没有行项目添加到履行中的错误。

有没有办法选择要完成的行?考虑一下,在查看销售订单时,您如何点击“履行”,然后可以单击要包含在该履行中的行项目的复选框。

谢谢

2 个答案:

答案 0 :(得分:1)

有一个名为“itemreceive”的交易列字段。此“itemreceive”字段等效于 UI 中“Item Fulfillment create record”页面上的“Fulfill”复选框。以下代码应该可以工作

//transform SO to create a new Item fulfillment
var fulfillment = record.transform({
  fromType: record.Type.SALES_ORDER,
  fromId: currentRecord.id,
  toType: record.Type.ITEM_FULFILLMENT,
  isDynamic: true
});

//get line count of newly created fulfillment
var lineCount = fulfillment.getLineCount({
    sublistId: 'item'
});

//for each line set the "itemreceive" field to true
for (var i = 0; i < lineCount; i++) {
  fulfillment.selectLine({
      sublistId: 'item',
      line: i
  });
  fulfillment.setCurrentSublistValue({
      sublistId: 'item',
      fieldId: 'itemreceive',
      value: true
  });

  //set other relevant sublist fields
  fulfillment.setCurrentSublistValue({
      sublistId: 'item',
      fieldId: 'fieldId',
      value: 'value'
  });
  fulfillment.commitLine({
      sublistId: 'item'
  });
}

//set any other relevant itemreceive fields
itemreceive.setValue({
  filedId: 'fieldId',
  value: 'value'
});

//save the newly created itemreceive
var itemreceiveId = itemreceive.save({
  enableSourcing: true, //optional, defaul is false
  ignoreMandatoryFields: true  //optional, defaul is false
});

答案 1 :(得分:0)

如果销售订单具有可履行的行,则履行行可能会出现未选中的履行复选框。这是通过设置 -> 会计 -> 会计首选项中的复选框“默认项目归零接收/完成”控制的;订单管理选项卡;履行部分。

考虑到您帐户中的效果,它可能会被选中,因此如果您只是创建并保存项目履行,则默认情况下不会履行任何行。

通常在编写执行脚本时,我会迭代这些行并执行以下操作:

 var shouldFulfill = someLogic();
 itemFulfillment.setSublistValue({sublistId:'item', fieldId:'itemreceive', line:idx, value:shouldFufill});

或者像你的情况isDynamic:true

itemFulfillment.setCurrentSublistValue({sublistId:'item', fieldId:'itemreceive', line:idx, value:shouldFufill});