通过项目收据生成多个批号库存(附代码):SuiteScript 1.0 Netsuite
Generate Multiple Lot Numbered Inventory through Item Receipt(Code attached): SuiteScript 1.0 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 = 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);
根据代码示例,它应该为每个项目创建两个批次,但它只会创建 1 最后一个,即 XZY2。
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);
您在此处尝试提交 库存详细信息 数量超过履行行定义的数量。
以上代码在SuiteScript2.
中的一个例子
注意:我发现 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();
我正在尝试生成多个批号库存,但它只创建一个批号并分配给该项目库存,不确定我哪里出错了。
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);
根据代码示例,它应该为每个项目创建两个批次,但它只会创建 1 最后一个,即 XZY2。
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);
您在此处尝试提交 库存详细信息 数量超过履行行定义的数量。
以上代码在SuiteScript2.
中的一个例子注意:我发现 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();