我正在尝试生成多个批次编号的库存,但是它仅创建一个批次编号并分配给该物料库存,不知道我要去哪里。
var poid =15513;
var sublistcount = 2;
var fromrecord;
var fromid;
var torecord;
var trecord;
var qty;
fromrecord = 'purchaseorder';
fromid = poid;
torecord = 'itemreceipt';
fulfillment_record = nlapiTransformRecord(fromrecord, fromid, torecord,true);
for(var i=1;i<=sublistcount;i++)
{
var warehousequantity= 2;
//var po_line_count = fulfillment_record.getLineItemCount('item');
fulfillment_record.selectLineItem('item', i);
fulfillment_record.setCurrentLineItemValue('item', 'itemreceive', 'F');
fulfillment_record.setCurrentLineItemValue('item', 'quantity', warehousequantity);
for(var j=1;j<=warehousequantity;j++)
{
var subrecord = fulfillment_record.editCurrentLineItemSubrecord('item', 'inventorydetail');
if(subrecord!=null){
subrecord = fulfillment_record.editCurrentLineItemSubrecord('item', 'inventorydetail');
subrecord.insertLineItem('inventoryassignment',j);
}else {
subrecord = fulfillment_record.createCurrentLineItemSubrecord('item', 'inventorydetail');
}
subrecord.selectLineItem('inventoryassignment', j);
subrecord.setCurrentLineItemValue('inventoryassignment', 'quantity', 2);
subrecord.setCurrentLineItemValue('inventoryassignment', 'itemreceive ', 'F');
subrecord.setCurrentLineItemValue('item', 'serialnumbers', 'XZY'+j);
subrecord.setCurrentLineItemValue('inventoryassignment', 'receiptinventorynumber','XYZ'+j);
subrecord.commitLineItem('inventoryassignment');
subrecord.commitLineItem('inventorydetail');
subrecord.commit();
fulfillment_record.commitLineItem('item');
fulfillment_record.commitLineItem('inventory');
}
}
var id = nlapiSubmitRecord(fulfillment_record, true, false);
根据代码示例,它应为每个项目创建两个批次,但最后一个项目(即XZY2)仅创建1。
答案 0 :(得分:2)
fulfillment_record.setCurrentLineItemValue('item', 'itemreceive', 'F');
subrecord.setCurrentLineItemValue('inventoryassignment', 'itemreceive ', 'F');
如果要实现,则无需将 itemreceive 显式标记为false。
subrecord.commitLineItem('inventorydetail');
您只能提交子列表行,因为 inventorydetail 不是子列表,所以不是必需的。
subrecord.commit();
您不需要显式提交子记录,因为子记录由NetSuite在保存父记录时自动保存。
subrecord.setCurrentLineItemValue('inventoryassignment', 'quantity', 2);
在这里,您要提交的库存明细数量要多于履行线上定义的数量。
SuemScript2 中上述代码的示例。
注意:我发现了NetSuite的一些局限性,即它不允许在动态模式下设置清单详细信息,因此我使用的是非动态模式
var poid = 15513;
var sublistcount = 2;
var fromrecord;
var fromid;
var torecord;
var trecord;
var qty;
fromrecord = 'purchaseorder';
fromid = poid;
torecord = 'itemreceipt';
fulfillment_record = record.transform({
fromType: fromrecord,
fromId: fromid,
toType: torecord,
isDynamic: false
});
var sublistCount = fulfillment_record.getLineCount({ sublistId: 'item' });
for (var i = 0; i < sublistcount; i++) {
var warehousequantity = 2;
fulfillment_record.setSublistValue({ sublistId: 'item', fieldId: 'quantity', value: warehousequantity, line: i });
var subrecord = fulfillment_record.getSublistSubrecord({ sublistId: 'item', fieldId: 'inventorydetail', line: i });
if (subrecord) {
// first insert a new line
for (var j = 0; j < warehousequantity; j++) {
subrecord.insertLine({ sublistId: 'inventoryassignment', line: j });
// set inventory quantity
subrecord.setSublistValue({ sublistId: 'inventoryassignment', fieldId: 'quantity', value: 1, line: j });
// set serialnumber
subrecord.setSublistValue({ sublistId: 'inventoryassignment',fieldId: 'serialnumbers', value: 'XZY' + i + j , line: j });
}
// don't commit/submit/save subrecord explicitly
// since NetSuite saves the sub-record when you save parent record
}
// since the record in non-dynamic mode
// we don't need to commit line
}
var id = fulfillment_record.save();