I am able to set header level fields, but can't se...
# suitescript
m
I am able to set header level fields, but can't seem to update the line level. Tried few combination. Getting the error: You have attempted an invalid sublist or line item operation. Do I save the Item Receipt record first, then load it and set the line? Also, would I need to set the inventory details if the quantities are different? if (poId) { const itemReceipt = record.transform({ fromType: record.Type.PURCHASE_ORDER, fromId: poId, toType: record.Type.ITEM_RECEIPT, isDynamic: true, }); itemReceipt.setValue({ fieldId: 'memo', value: "Set in Auto Item Receipt Creation" }); const lineCount = itemReceipt.getLineCount({ sublistId: 'item' }); for (let i = 0; i < lineCount; i++) { const qty = itemReceipt.setCurrentSublistValue({ sublistId: 'item', fieldId: 'quantity', value: '10' }); log.debug({title: "Quantity", details: qty}); } const itemReceiptId = itemReceipt.save(); log.debug({title: "Item Receipt ID", details: itemReceiptId}); }
n
In your loop if you use setCurrentSublistValue() and dynamic mode, youll need to
itemReceipt.selectLine({sublistId: 'item', line: i})
before you set the value. Then
itemReceipt.commitLine({sublistId: 'item'})
after you set the value
👌 1
m
That's great. I did see the selectLine option, but my intellisense was indicating it's not a valid method! So since my quantity on the Item Receipt is different to that of the PO, I get error asking me to configure the inventory detail. So now I've started on that, but it's asking me to provide a serial number, and even though I just want to update the first line with the quantity, I did try to provide the serial number, but doesn't quite work. Any ideas on this?
Copy code
for (let i = 0; i < lineCount; i++) {
                               itemReceipt.selectLine({
                                   sublistId: 'item',
                                   line: i
                               });
                               itemReceipt.setCurrentSublistValue({
                                   sublistId: 'item',
                                   fieldId: 'quantity',
                                   value: '1'
                               });
                               const inventoryDetailSubrecord = itemReceipt.getCurrentSublistSubrecord({
                                   sublistId: 'item',
                                   fieldId: 'inventorydetail'
                               });
 
                               inventoryDetailSubrecord.setCurrentSublistValue({
                                   sublistId: 'inventoryassignment',
                                   fieldId: 'quantity',
                                   value: '1'
                               });
                               inventoryDetailSubrecord.setCurrentSublistValue({
                                   sublistId: 'inventoryassignment',
                                   fieldId: 'issueinventorynumber',
                                   value: '12345a'
                               });
                               inventoryDetailSubrecord.commitLine({
                                   sublistId: 'inventoryassignment'
                               });
 
                               itemReceipt.commitLine({
                                   sublistId: 'item'
                               });
                           }
                           const itemReceiptId = itemReceipt.save();
                           log.debug({title: "Item Receipt ID", details: itemReceiptId});
                       }
b
you are setting the wrong field on the inventory detail, make the item receipt you want in the ui, and then log one of its inventory details in script
m
Looking at the inventory details log, the two fields I'm setting is there. sublists > currentline > issueinventorynumber & quantity. What I'm I missing?
Oh, I think the field id might be receiptinventorynumber as after using that, the error is now with the quantity! Thanks for the headups
I am overriding the quantity on the item receipt, which means I also need to update the inventory details. The original quantity (from the PO) is 10, but I set it to 1 on the Item Receipt. After the script ends, I get: "The total inventory detail quantity must be 1. Looking at the log, I see sublists: inventoryassignment: currentline - all blank. Below that, "line 1" - this appears to have the data. It shows my original quantity of 10. Does this mean, my code is not setting line 1? Or something else I am missing?
b
you need more practice using dynamic mode
the order you set fields matters in dynamic mode
you need to set them in the same order you would in the ui since it does sourcing just like it does in the ui
m
Actually I did change the order. So now, I'm setting the quantity on the item receipt, then I'm getting inventory details, setting serial number then the quantity, the same order as I would in the UI. Finally, Commit the inventory line, then the item line. Can't see the issue 😕
b
whats does the code look like
m
I will eventually retrieve the quantity from elsewhere, but for now I am just trying to hard code a value just to see the inventory detail line can be updated. This is block that creates the IR from the PO:
Copy code
if (poId) {
                            const itemReceipt = record.transform({
                                fromType: record.Type.PURCHASE_ORDER,
                                fromId: poId,
                                toType: record.Type.ITEM_RECEIPT,
                                isDynamic: true,
                            });
                            itemReceipt.setValue({
                                fieldId: 'memo',
                                value: "Set in Auto Item Receipt Creation"
                            });
                            const lineCount = itemReceipt.getLineCount({
                                sublistId: 'item'
                            });
                            for (let i = 0; i < lineCount; i++) {
                                itemReceipt.selectLine({
                                    sublistId: 'item',
                                    line: i
                                });

                                itemReceipt.setCurrentSublistValue({
                                    sublistId: 'item',
                                    fieldId: 'quantity',
                                    value: '5'
                                });

                                const inventoryDetailSubrecord = itemReceipt.getCurrentSublistSubrecord({
                                    sublistId: 'item',
                                    fieldId: 'inventorydetail'
                                });

                                log.debug({title: "Inventory Details Object", details: inventoryDetailSubrecord});

                                inventoryDetailSubrecord.setCurrentSublistValue({
                                    sublistId: 'inventoryassignment',
                                    fieldId: 'receiptinventorynumber',
                                    value: '123x',
                                });

                                inventoryDetailSubrecord.setCurrentSublistValue({
                                    sublistId: 'inventoryassignment',
                                    fieldId: 'quantity',
                                    value: '5',
                                });

                                inventoryDetailSubrecord.commitLine({
                                    sublistId: 'inventoryassignment'
                                });

                                itemReceipt.commitLine({
                                    sublistId: 'item'
                                });
                            }
                            const itemReceiptId = itemReceipt.save();
                            log.debug({title: "Item Receipt ID", details: itemReceiptId});
                        }
b
same answer actually, you need more practice with dynamic mode
go back to what Nathan told you about selecting lines
in general you will need to select an existing line or the new line
you also want to make sure you know how to do this operation in the ui, its extremely unusual to want to assign 5 quantity to one serial number
m
I know - I do scripting once every few months! Anyway, I did follow what Nathan said. Since my record is loaded in dynamic mode I used selectLine, then set the quantity on the line - this works when I don't change the quantity. 95% I won't need to change the inventory details as the PO to IR will be a straight forward transform. But on the odd case, the quantity needs updating. I used 5 as just a test. Updating the inventory details in the UI is no issue - works fine. It's all these select methods that's messing with my head!
b
Copy code
const inventoryDetailSubrecord = itemReceipt.getCurrentSublistSubrecord({
                                    sublistId: 'item',
                                    fieldId: 'inventorydetail'
                                });

                                log.debug({title: "Inventory Details Object", details: inventoryDetailSubrecord});

                                inventoryDetailSubrecord.setCurrentSublistValue({
                                    sublistId: 'inventoryassignment',
                                    fieldId: 'receiptinventorynumber',
                                    value: '123x',
                                });

                                inventoryDetailSubrecord.setCurrentSublistValue({
                                    sublistId: 'inventoryassignment',
                                    fieldId: 'quantity',
                                    value: '5',
                                });

                                inventoryDetailSubrecord.commitLine({
                                    sublistId: 'inventoryassignment'
                                });
👍 1
where do you select the line
are you sure you are working with a serialized inventory item, those are one per line in the ui
m
Uff, I am blind! I'm now selecting the line, and managed to set it. Thanks.
Defo using serial number, I just used a bad test example. Ultimately, needed to be able to update inventory details, which it does now. Much thanks!