I've been wrestling with this for a while now. It may be a bug in NetSuite, but thought I'd consult the SuiteScript ninjas before conceeding to that idea.
Here is the scenario:
I have a sales order with a line for a lot numbered inventory item that has the inventory detail pre-filled out with lot information:
Here are the contents of that inventory detail:
I'm trying to script the fulfillment for that sales order, but I need to change the inventory detail at the time of fulfillment. This works fine and is permissible in the NetSuite UI, but I can not get a SuiteScript Restlet to do the same. Here is the same code from within the Restlet:
function runFullfillmentTest() {
var fulfillment = record.transform({
fromType: 'salesorder',
fromId: 21424,
toType: 'itemfulfillment'
});
var fulfillmentLineCount = fulfillment.getLineCount({
sublistId: 'item'
});
for (var i = 0; i < fulfillmentLineCount; i++) {
fulfillment.setSublistValue({
sublistId: 'item',
line: i,
fieldId: 'itemreceive',
value: false
});
}
// Orderline 3 has the following inventory details pre-set
// Line | Lot Number | Quantity
// 0 | L0001 | 2
// 1 | L0002 | 1
// 2 | L0003 | 1
var fulfillmentLineForItem = fulfillment.findSublistLineWithValue({
sublistId: 'item',
fieldId: 'orderline',
value: '3'
});
fulfillment.setSublistValue({
sublistId: 'item',
line: fulfillmentLineForItem,
fieldId: 'itemreceive',
value: true
});
fulfillment.setSublistValue({
sublistId: 'item',
line: fulfillmentLineForItem,
fieldId: 'quantity',
value: '5'
});
var inventorydetailForFulfillmentLine = fulfillment.getSublistSubrecord({
sublistId: 'item',
fieldId: 'inventorydetail',
line: fulfillmentLineForItem
});
inventorydetailForFulfillmentLine.setValue({
fieldId: 'quantity',
value: '5'
});
var existingLineCount = inventorydetailForFulfillmentLine.getLineCount({
sublistId: 'inventoryassignment'
});
for (var i = 0; i < existingLineCount; i++) {
inventorydetailForFulfillmentLine.removeLine({
sublistId: 'inventoryassignment',
line: 0
});
}
inventorydetailForFulfillmentLine.insertLine({
sublistId: 'inventoryassignment',
line: 0
});
inventorydetailForFulfillmentLine.setSublistValue({
sublistId: 'inventoryassignment',
line: 0,
fieldId: 'issueinventorynumber',
value: '154' // L0003
});
// Interestingly enough, if you take out the line below, you'll
// get the error: "USER_ERROR : Please enter value(s) for: Serial/Lot Number, Bin, Quantity"
// So its almost like issueinventorynumber and quantity aren't being seen as
// being set by NetSuite
// I think it does see binnumber, but thinks it is invalid because it
// believes the issueinventorynumber to be is blank
inventorydetailForFulfillmentLine.setSublistValue({
sublistId: 'inventoryassignment',
line: 0,
fieldId: 'binnumber',
value: '111' // W.3.0.0
});
inventorydetailForFulfillmentLine.setSublistValue({
sublistId: 'inventoryassignment',
line: 0,
fieldId: 'quantity',
value: '5'
});
// This will throw error:
// "INVALID_FLD_VALUE : You have entered an Invalid Field Value 111 for the following field: binnumber"
return fulfillment.save();
}
As shown in the comments, I get the error:"INVALID_FLD_VALUE : You have entered an Invalid Field Value 111 for the following field: binnumber"
In this case 111
is the valid internalid for bin W.3.0.0
Interestingly enough, if remove the line that sets the binnumber to 111
then I get the error:
USER_ERROR : Please enter value(s) for: Serial/Lot Number, Bin, Quantity
Which looks like I am missing the lot and quantity fields, but I just set those? I think it complains about 111
being invalid because it believes the lot number has not been set, and needs that to validate the binnumber.
Any help or other ideas to try are appreciated. I've also tried re-using the existing lines (instead of inserting a new one), but no luck.