How can I configure the inventory detail on a reco...
# suitescript
n
How can I configure the inventory detail on a record body (work order completion to be specific). Here is my code snippet. But I kept getting an error
Copy code
let invDetail = woCompletionRec.getSubrecord({
     fieldId: 'inventorydetail'
 });


 invDetail.selectNewLine({sublistId: 'inventoryassignment'})
 invDetail.setCurrentSublistValue({
     sublistId: 'inventoryassignment',
     fieldId: 'receiptinventorynumber',
     value: inventoryNum
 });
 invDetail.setCurrentSublistValue({
     sublistId: 'inventoryassignment',
     fieldId: 'binnumber',
     value: defaultBin
 });
 invDetail.setCurrentSublistValue({
     sublistId: 'inventoryassignment',
     fieldId: 'inventorystatus',
     value: defaultStatus
 });
 invDetail.setCurrentSublistValue({
     sublistId: 'inventoryassignment',
     fieldId: 'quantity',
     value: 1
 })

invDetail.commitLine({sublistId: 'inventoryassignment'});
n
What’s the error you’re getting?
n
@Nathan L {"type":"error.SuiteScriptError","name":"SSS_INVALID_SUBLIST_OPERATION","message":"You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.","stack":["Error\n at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js37113)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js11524)\n at Object.afterSubmit (/SuiteScripts/st_prod/ST_UE_SAR_to_WO_Completion.js14650)"],"cause":{"type":"internal error","code":"SSS_INVALID_SUBLIST_OPERATION","details":"You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.","userEvent":null,"stackTrace":["Error\n at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js37113)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js11524)\n at Object.afterSubmit (/SuiteScripts/st_prod/ST_UE_SAR_to_WO_Completion.js14650)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":true}
n
For your inventoryNum field try using `issueinventorynumber`instead of
receiptinventorynumber
n
@Nathan L I tried that, but I'd get another error saying : please enter Serial/lot Number
n
shoot. and is your variable inventoryNum the internal id of the serial number record or is it the text value.
n
It is a text value
n
Ah gotcha. I know it different for the type of record. Mines using the internalid of the inventoryNumber record associated with the serial number. But i guess if you are trying to create serial numbers then you wouldnt have that
n
correct, yeah, it is a text field in the UI
n
Is it a work order record you are working off of?
n
I am transforming work order to a work order completion
n
Gotcha. Im sorry im not really familiar with the work order completion record. I may have wasted your time. The only other thing would be to try it in static mode instead of dynamic. But then you lose all your auto populated fields from the transform
n
no worries. Thanks for being willing to help! Yeah, tried to set dynamic is false, then the error is that I need to configure the inventory details haha
n
Instead of selectNewLine() have you tried just selecting the first line and setting the values?
Copy code
let invDetail = woCompletionRec.getSubrecord({
     fieldId: 'inventorydetail'
 });


 invDetail.selectLine({sublistId: 'inventoryassignment', line: 0})
 invDetail.setCurrentSublistValue({
     sublistId: 'inventoryassignment',
     fieldId: 'receiptinventorynumber',
     value: inventoryNum
 });
 invDetail.setCurrentSublistValue({
     sublistId: 'inventoryassignment',
     fieldId: 'binnumber',
     value: defaultBin
 });
 invDetail.setCurrentSublistValue({
     sublistId: 'inventoryassignment',
     fieldId: 'inventorystatus',
     value: defaultStatus
 });
 invDetail.setCurrentSublistValue({
     sublistId: 'inventoryassignment',
     fieldId: 'quantity',
     value: 1
 })

invDetail.commitLine({sublistId: 'inventoryassignment'});
n
Yep, did that and insert line. Same error...
n
🫥 i hate inventory detail records.
n
SAME!!!!!!!!!!!
n
Ok im looking at the record browser now to see if its helpful in any way. It looks like you have to set quantity to build first before you can configure inventorydetail
n
Yes, I am setting that before configuring the inventory detail
b
you havent shared which line is causing the error
but the error message suggests its on save, which means you probably want to disable other user event scripts / workflows
n
I figured it out...It was another mandatory fields on the work order completion that has to be filled out (has nothing to do with inventory detail...), even if I had ignoreMandatoryFields: true on record save 🤦
😩 1
Thank you @Nathan L and @battk for all the help
n
Glad you got it working!
😄 1