Reputation: 33
Trying to transform a NetSuite sales order using
var fulfillment = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: currentRecord.id,
toType: record.Type.ITEM_FULFILLMENT,
isDynamic: true
});
getting the error "USER_ERROR","message":"You must enter at least one line item for this transaction."
The fulfillment contains 7 line items but after fulfillment.save() it returns the error that there are no line items added to the fulfillment.
Is there a way to select which rows to fulfill? Thinking about how, when looking at the sales order, you click fulfill and then can click a checkbox for which line items you want to include in that fulfillment.
thanks
Upvotes: 3
Views: 4288
Reputation: 764
There's a Transaction Column field named "itemreceive". This 'itemreceive' field is equivalent to the 'Fulfill' checkbox found on the Item Fulfillment create record page in the UI. The following code should work
//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
});
Upvotes: 2
Reputation: 15377
If the sales order has lines that are fulfillable the fulfillment lines are probably coming up with the Fulfill checkbox un-checked. This is controlled via a checkbox 'DEFAULT ITEMS TO ZERO RECEIVED/FULFILLED' in Setup -> Accounting -> Accounting Preferences; Order Management Tab; Fulfillment section.
Given the effect in your account it is probably checked so no lines by default will be fulfilled if you just create and save an item fulfillment.
Generally when scripting a fulfillment I'll iterate the lines and do something like:
var shouldFulfill = someLogic();
itemFulfillment.setSublistValue({sublistId:'item', fieldId:'itemreceive', line:idx, value:shouldFufill});
or like in your case with isDynamic:true
itemFulfillment.setCurrentSublistValue({sublistId:'item', fieldId:'itemreceive', line:idx, value:shouldFufill});
Upvotes: 0