“UNEXPECTED_ERROR” for Inventory Adjustment
I am getting an Unexpected Error message when I try to script a very simple inventory adjustment. I tried this both in server and client, and I tried both isDynamic=true and false, but I’m still getting the same error.
I am able to create an inventory adjustment on thru UI with no problems with the current values I’m scripting.
Can anyone eyeball possibly what I’m doing wrong? I have been able to script adjustments in the past so I’m hoping it’s a simple fix. Thank you!
isDynamic = true:
var oInventoryAdj = record.create({ type: record.Type.INVENTORY_ADJUSTMENT, isDynamic: true, }); oInventoryAdj.setValue({fieldId: 'memo', value: "February Adjustments", }); oInventoryAdj.setValue({fieldId: 'trandate', value: new Date("02/26/2021"), }); oInventoryAdj.setValue({fieldId: 'account', value: 249, }); oInventoryAdj.insertLine({sublistId: 'inventory', line: 0 }); oInventoryAdj.selectLine({sublistId: 'inventory', line: 0 }); oInventoryAdj.setCurrentSublistValue({ sublistId: 'inventory', fieldId: 'location', line: 0, value: '1', }); oInventoryAdj.setCurrentSublistValue({ sublistId: 'inventory', fieldId: 'item', line: 0, value: '1495', }); oInventoryAdj.setCurrentSublistValue({ sublistId: 'inventory', fieldId: 'adjustqtyby', line: 0, value: '7', }); oInventoryAdj.commitLine({ sublistId: 'inventory', line: 0, }); oInventoryAdj.save();
isDynamic = false
var oNetsuiteTransactionObject = record.create({ type: record.Type.INVENTORY_ADJUSTMENT, isDynamic: false, }); oNetsuiteTransactionObject.setText({fieldId: 'memo', text: "February Adjustments", }); oNetsuiteTransactionObject.setValue({fieldId: 'account', value: 249, }); oNetsuiteTransactionObject.setSublistValue({ sublistId: 'inventory', fieldId: 'location', line: 1, value: '1', }); oNetsuiteTransactionObject.setSublistValue({ sublistId: 'inventory', fieldId: 'item', line: 1, value: '1495', }); oNetsuiteTransactionObject.setSublistValue({ sublistId: 'inventory', fieldId: 'adjustqtyby', line: 1, value: '7', }); oNetsuiteTransactionObject.save();
Your dynamic code looks normal. I wouldnt use insertLine and selectLine, simply use Record.selectNewLine. That said, your code should work on a non one world account. If its one world, you need to set the subsidiary field first.
Your non dynamic code should start at line 0, not line 1. Again, i dont think that error would cause an unexpected error,
Make sure that there are no workflows or user event scripts that could be causing your unexpected error.
I definitely think that the issue is not using selectNewLine
. With any luck that will fix the problem.
First of all i am assuming you are not working for numbered items i.e serialized/lot numbered items .
In Dynamic Mode, sequence of value setting matters , so at line setting you should set the field in following sequence :
item,
location ,
adjustqtyby
Are you using serialized inventory? If so you may need o add the inventory detail for he adjustment as well. SuiteAnswers 61069.
…
inventoryDetailSubrecord = rec.getSublistSubrecord({
sublistId: ‘item’,
fieldId: ‘inventorydetail’,
line: 0
});
……
subrecordInvDetail.setSublistValue({
sublistId: ‘inventoryassignment’,
fieldId: ‘receiptinventorynumber’,
line: 0,
value: ‘012345’
});
…
Also there is SuiteAnswer 94552 with the same error you have. Solution is to check hat there are not ay customizations setting the Location in he man body field