Hello. I'm trying to create a Work Order Issue fro...
# suitescript
b
Hello. I'm trying to create a Work Order Issue from Work Order. I'm doing it from
record.transform()
however, Components sublist is a challenge for me.
Copy code
var woIssueRec = record.transform({fromType:record.Type.WORK_ORDER, fromId: woID, toType:record.Type.WORK_ORDER_ISSUE, isDynamic:false});
for(let i=0; i<3;i++){
woIssueRec.insertLine({sublistId:"component", line:i, ignoreRecalc:false});
And here comes the most challenge part.
Copy code
let compInventoryDetailRec = woIssueRec.getSublistSubrecord({
                        sublistId: 'component',
                        fieldId: 'componentinventorydetail',
                        line: i
                    });

                    log.debug('component loop', 'insertLine2');
                    compInventoryDetailRec.insertLine({
                        sublistId: 'inventoryassignment ',
                        line: 0
                    });
compInventoryDetailRec.setSublistValue({
                        sublistId: 'inventoryassignment',
                        fieldId: 'binnumber',
                        line: 0,
                        value: 'binNumber'
                    });
                    log.debug('component loop', 'insertLine4');
                    compInventoryDetailRec.setSublistValue({
                        sublistId: 'inventoryassignment',
                        fieldId: 'issueinventorynumber',
                        line: 0,
                        value: 'lotNumber'
                    });
But this shows me the error says
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.
Could I know what's wrong please? Component is a sublist, Inventory Detail is subrecord of sublist and InventoryAssignment is sublist of Inventory Detail. Am I right?
e
Are you getting to any of those logs? From my experience, that error is message is going to be related to "isDynamic: false" not playing nicely with one of your sublist calls (one of; insertLine, getSublistSubrecord, or setSublistValue)
b
I think when we use record.transform, we can't add line for Work Order Issue. I could get all items are added in Components sublist in UI
e
Did you try setting isDynamic to true?
b
yes, no difference
e
I'm not too familiar with Work Order Issues, but in the UI when you hit the button to go from Work Order -> Work Order Issue... is the item
component
list already populated?
b
yes
e
Then you likely don't need this line:
Copy code
woIssueRec.insertLine({sublistId:"component", line:i, ignoreRecalc:false});
Unless you're trying to add an additional component that isn't on the original Work Order at all
b
yes exactly
e
Are you able to add new components to the Work Order Issue in the UI?
b
No
e
Ok, so that's the issue. If NS doesn't let you add component lines to the Work Order Issue it won't let you do it via scripting either (or so that's the case 99% of the time)
I'd relate it to Sales Orders and Item Fulfillments. When you hit "Fulfill Order" on a Sales Order, NetSuite doesnt allow you to add any items to the Item Fulfillment since you can (should) only be shipping items that are on the Sales Order.
b
Yes I see
Do you know how to set Inventory Detail in that sublist please?
e
Here's a snippet of code I have for setting Inventory Detail on an Item Fulfillment... you should be able to tweak it to get what you're needing
Copy code
var fulfillmentLineCount = fulfillment.getLineCount({
                    sublistId: 'item'
                });

                for (var i = 0; i < fulfillmentLineCount; i++) {

                    if (parseFloat(allInfo.table[i].quantityCompleted) > 0) {
                        fulfillment.setSublistValue({
                            sublistId: 'item',
                            line: i,
                            fieldId: 'quantity',
                            value: parseFloat(allInfo.table[i].quantityCompleted)
                        });

                    }
                    if (allInfo.table[i].pickedSerials) {
                        let inventoryDetailRecord = fulfillment.getSublistSubrecord({
                            sublistId: 'item',
                            fieldId: 'inventorydetail',
                            line: i
                        });

                        for (j = 0; j < allInfo.table[i].pickedSerials.length; j++) {
                            inventoryDetailRecord.setSublistText({
                                sublistId: 'inventoryassignment',
                                fieldId: 'issueinventorynumber',
                                line: j,
                                text: allInfo.table[i].pickedSerials[j]
                            });
                            inventoryDetailRecord.setSublistValue({
                                sublistId: 'inventoryassignment',
                                fieldId: 'quantity',
                                line: j,
                                value: 1
                            });
                        }
                    }

                }

                var itemReceiptId = fulfillment.save();
b
Thank you
don't need to insertLine for 'inventoryassignment'?
e
I didn't in my case, but it's worth noting when I transformed the Sales Order -> Item Fulfillment, I didn't pass the isDynamic key at all, so it's set to whatever the default value is (I don't know off hand)
Tweak it and give it a try--- reply back with your results and we can chat more
b
Thank you. I really appreciate your help
e
Sure thing!