I'm having some issues with adding item groups ser...
# suitescript
x
I'm having some issues with adding item groups server-side. The idea is that I am copying the lines from one transaction onto another. In the code block that checks if the item type is a Group, it keeps telling me to input a value for 'amount'. I've also tried explicitly setting an amount in that same block, but still the same error when I go to commit the item.
Copy code
for (let i = 0; i < q.getLineCount('item'); i++)
                {
                    if (groupItem)
                    {
                        opp.selectLine({sublistId: 'item',line: i})
                        opp.setCurrentSublistValue('item', 'quantity', q.getSublistValue('item', 'quantity', i))
                        opp.setCurrentSublistValue('item', 'rate', q.getSublistValue('item', 'rate', i))
                        opp.setCurrentSublistValue('item', 'amount', q.getSublistValue('item', 'amount', i))
                        opp.setCurrentSublistValue('item', 'price', q.getSublistValue('item', 'price', i))
                        igTotal += opp.setCurrentSublistValue('item', 'amount', q.getSublistValue('item', 'amount', i))
                    }
                    if (q.getSublistValue('item', 'itemtype', i) == 'EndGroup')
                    {
                        opp.setCurrentSublistValue('item', 'amount', igTotal)
                        groupItem = false
                        continue
                    }
                    if (!groupItem && q.getSublistValue('item', 'itemtype', i) != 'EndGroup' && !groupItem)
                    {
                        opp.selectNewLine({sublistId: 'item'})
                        opp.setCurrentSublistValue('item', 'item', q.getSublistValue('item', 'item', i))
                        opp.setCurrentSublistValue('item', 'quantity', q.getSublistValue('item', 'quantity', i))
                        if (opp.getCurrentSublistValue('item', 'itemtype') == "Group")
                        {
                            groupItem = true
                            opp.setCurrentSublistValue('item', 'amount', 123)
                            opp.commitLine({sublistId: 'item'}) //SCRIPT FAILS HERE.
                            continue 
                        }
                        opp.setCurrentSublistValue('item', 'rate', q.getSublistValue('item', 'rate', i))
                        opp.setCurrentSublistValue('item', 'amount', q.getSublistValue('item', 'amount', i))
                        opp.commitLine({sublistId: 'item'})                   
                    }

                }
b
make your code actually commit every line, your code currently only commits it sometimes
start hardcoding or at least start logging your amounts, you are not setting sane numbers for all your amounts
x
@battk opp.setCurrentSublistValue('item', 'groupsetup', true) got me past that commit that it kept failing on. Things are a little weird still, and it doesn't like me inputting data around the price in the other transaction, but this will be something I explore over the next few days.