How to update default discount on item price level...
# ask-stanley-ai
v
How to update default discount on item price level using suitelet
c
AI generated answer (using internal Slack threads):
To update the default discount on item price level using a Suitelet, you can use the
record
module to load the item record and then manipulate the sublist values. Here is a sample code snippet that demonstrates how to do this:
Copy code
javascript
/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define(['N/record'], function(record) {
    function onRequest(context) {
        if (context.request.method === 'POST') {
            var itemId = context.request.parameters.itemid; // replace with your item id
            var newDiscount = context.request.parameters.discount; // replace with your new discount

            // Load the item record in DYNAMIC mode
            var itemRecord = record.load({
                type: record.Type.INVENTORY_ITEM,
                id: itemId,
                isDynamic: true // Dynamic mode allows sublist manipulation
            });

            var priceCount = itemRecord.getLineCount({sublistId: 'price1'});

            for (var i = 0; i < priceCount; i++) {
                var priceLevel = itemRecord.getSublistValue({
                    sublistId: 'price1',
                    fieldId: 'pricelevel',
                    line: i
                });

                if (priceLevel == '1') { // replace with your price level
                    itemRecord.selectLine({
                        sublistId: 'price1',
                        line: i
                    });

                    itemRecord.setCurrentSublistValue({
                        sublistId: 'price1',
                        fieldId: 'price',
                        value: newDiscount
                    });

                    itemRecord.commitLine({ sublistId: 'price1' });
                }
            }

            itemRecord.save();
        }
    }

    return {
        onRequest: onRequest
    };
});
This Suitelet loads the item record in dynamic mode, which allows for sublist manipulation. It then iterates over each line in the 'price1' sublist (which represents the item's pricing levels), and if the price level matches the desired level, it updates the price to the new discount value. Please replace
'1'
with your price level and replace
newDiscount
with your new discount. Also, replace
itemid
and
discount
with your actual item id and discount in the POST request. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.811712
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.808954954
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.808256149
Please provide your feedback on this answer.