【问题标题】:How do you select line items to fulfill when transforming a netsuite sales order to fulfillment?在将 netsuite 销售订单转换为履行时,您如何选择要履行的行项目?
【发布时间】:2021-07-22 19:34:36
【问题描述】:
尝试使用
转换 NetSuite 销售订单
var fulfillment = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: currentRecord.id,
toType: record.Type.ITEM_FULFILLMENT,
isDynamic: true
});
收到错误“USER_ERROR”、“消息”:“您必须为此交易输入至少一个行项目。”
履行包含 7 个订单项,但在履行。save() 之后它返回错误,即没有订单项添加到履行。
有没有办法选择要完成的行?想一想,在查看销售订单时,您如何单击履行,然后可以单击复选框,以选择要包含在该履行中的行项目。
谢谢
【问题讨论】:
标签:
javascript
transform
netsuite
suitescript
【解决方案1】:
有一个名为“itemreceive”的交易列字段。此“itemreceive”字段等同于 UI 中“项目履行创建记录”页面上的“履行”复选框。以下代码应该可以工作
//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
});
【解决方案2】:
如果销售订单具有可履行的行,则履行行可能会出现未选中的履行复选框。这通过设置 -> 会计 -> 会计首选项中的“默认项目为零接收/完成”复选框进行控制;订单管理选项卡;履行部分。
鉴于您帐户中的效果,它可能已被选中,因此如果您只是创建并保存项目履行,则默认情况下不会履行任何行。
通常在编写实现脚本时,我会迭代这些行并执行以下操作:
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});