Has anyone managed to get a price level AND rate/p...
# suitescript
c
Has anyone managed to get a price level AND rate/price to change on an invoice when the customer has group pricing? I've tried so many different ways to override the group pricing price level. I've gotten it to change the price level, but the actual rate/price still shows the group pricing price and not the price associated with the selected price level.
This will initially set the price level and price correctly, but if you change the quantity, the rate goes back to the group pricing rate, even though the price level still displays a different price level:
Copy code
async function postSourcing(context) {

            if (context.sublistId == 'item' && context.fieldId == 'item') {

                try {

                    const currentRecord = context.currentRecord;
                    const itemId = await currentRecord.getCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'item'
                    });
                    const currentPriceLevel = await currentRecord.getCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'price'
                    });
                    let description = await currentRecord.getCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'description'
                    })
                    const currentQuantity = await currentRecord.getCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'quantity'
                    })
                    const currentQuantityConversionRate = await currentRecord.getCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'unitconversionrate'
                    })

                    if (!itemId) return;
                    if (!priceLevelsToChange.includes(currentPriceLevel)) return;

                    const saleOrCloseoutData = await getSaleOrCloseoutdata(itemId);

                    const priceLevel = saleOrCloseoutData?.priceLevel;
                    const rate = saleOrCloseoutData?.price;
                    let saleEndDate;
                    if (saleOrCloseoutData?.saleEndDate) saleEndDate = moment(saleOrCloseoutData.saleEndDate).format('MM/DD/YYYY')

                    if (priceLevel) {
                        if (priceLevel == salesPriceLevel) {
                            description += `\n This item is on sale until ${saleEndDate}.`;
                        } else {
                            description += `\n This item is on sale as a Closeout item.`;
                        }
                        await currentRecord.setCurrentSublistValue({
                            sublistId: 'item',
                            fieldId: 'price',
                            value: priceLevel,
                            forceSyncSourcing: true,
                            ignoreFieldChange: true
                        });
                        await currentRecord.setCurrentSublistValue({
                            sublistId: 'item',
                            fieldId: 'description',
                            value: description,
                            forceSyncSourcing: true
                        });
                        await currentRecord.setCurrentSublistValue({
                            sublistId: 'item',
                            fieldId: 'rate',
                            value: rate,
                            forceSyncSourcing: true
                        })
                        await currentRecord.setCurrentSublistValue({
                            sublistId: 'item',
                            fieldId: 'amount',
                            value: Number(currentQuantity) * Number(currentQuantityConversionRate) * rate,
                            forceSyncSourcing: true
                        })
                    }
                } catch (error) {
                    handleAndEmailError(error);
                }

            };
        };