Hi, I am trying to create an invoice where the item is an inventory item that uses a bin. I checked and I have enough inventory for this item. I am able to commit the line for the inventory details but I get the error message when the invoice is committed. I actually followed the script in the support page. I have no idea what is missing. I would appreciate any help. Thank you in advance!
Here's the script I am using for my testing. This is exactly (except the ids) in the support page.
/**
* @NApiVersion 2.1
* @NScriptType ScheduledScript
*/
define(['N/record', 'N/log'], (record, log) => {
function execute(context) {
// Create the purchase order.
var rec = record.create({
type: record.Type.INVOICE,
isDynamic: true
});
// Set body fields on the invoice
rec.setValue({
fieldId: 'entity',
value: '1537'
});
rec.setValue({
fieldId: 'location',
value: '4'
});
// Create one line in the item sublist.
rec.selectNewLine({
sublistId: 'item'
});
rec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: '1949'
});
rec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: 1
});
// Create the subrecord for that line.
var subrec = rec.
getCurrentSublistSubrecord({
sublistId: 'item',
fieldId: 'inventorydetail'
});
// Add a line to the subrecord's inventory assignment sublist.
subrec.selectNewLine({
sublistId: 'inventoryassignment'
});
subrec.setCurrentSublistValue({
sublistId: 'inventoryassignment',
fieldId: 'quantity',
value: 1 });
subrec.setCurrentSublistValue({
sublistId: 'inventoryassignment',
fieldId: 'location',
value: 4 });
subrec.setCurrentSublistValue({
sublistId: 'inventoryassignment',
fieldId: 'binnumber',
value: 1010 });
// Save the line in the subrecord's sublist.
subrec.commitLine({
sublistId: 'inventoryassignment' });
// Save the line in the record's sublist
rec.commitLine({
sublistId: 'item' });
// Save the record.
try {
var recId = rec.save();
log.debug({
title: 'Record created successfully',
details: 'Id: ' + recId});
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
}
return { execute };
});