RE: “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();

 

 

 

 

yayinternets Rookie Asked on February 26, 2021 in SuiteScript.
Add Comment
3 Answers

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.

Intermediate Answered on February 26, 2021.

I definitely think that the issue is not using selectNewLine.  With any luck that will fix the problem.

on March 1, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.