Hello Everyone, I am trying to update the base pri...
# suitescript
v
Hello Everyone, I am trying to update the base price at the item price level, but it is not updating.
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define(['N/ui/serverWidget', 'N/search', 'N/record', 'N/log', 'N/runtime'],
    function(serverWidget, search, record, log, runtime) {

        function onRequest(context) {
            var form = serverWidget.createForm({
                title: 'Select Pricing Category'
            });

            if (context.request.method === 'GET') {
                // Create a dropdown field for Pricing Categories
                var categoryField = form.addField({
                    id: 'pricing_category',
                    type: serverWidget.FieldType.SELECT,
                    label: 'Pricing Category'
                });

                // Perform a search for all pricing groups
                var categorySearch = search.create({
                    type: "pricinggroup",
                    columns: ["name", "internalid"]
                });

                var categoryResults = categorySearch.run().getRange({ start: 0, end: 100 });

                // Add options to the dropdown
                categoryResults.forEach(function (result) {
                    categoryField.addSelectOption({
                        value: result.getValue("internalid"),
                        text: result.getValue("name")
                    });
                });

                // Add a submit button to the form
                form.addSubmitButton('Submit');

                context.response.writePage(form);
            } else {
                // If the form is submitted, get the selected value (ID)
                var selectedCategoryId = context.request.parameters.pricing_category;
                log.debug('Selected Category ID:', selectedCategoryId);

                // Perform the search using the selected category ID (pricing category)
                var itemSearch = search.create({
                    type: search.Type.ITEM,
                    filters: [
                        ['custitem_almet_price_category_', 'is', selectedCategoryId]
                    ],
                    columns: ['internalid']
                });

                var results = itemSearch.run().getRange({ start: 0, end: 1 });

                if (results.length > 0) {
                    results.forEach(function (result) {
                        var itemId = result.getValue('internalid');
                        log.debug('Item ID:', itemId);

                        // 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
                        });

                      log.debug('itemRecord',itemRecord);


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

                       log.debug('priceCount',priceCount);

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

                           log.debug('priceLevel',priceLevel);
                        if (priceLevel == '1') { // replace with your price level

                          itemRecord.selectLine({
                                   sublistId: 'price1',
                                  line: i
                          });

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

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

                     itemRecord.save();
                    });

                    log.debug('Updated Items Based on Selected Category ID');
                } else {
                    log.error('No items found for the selected pricing category.');
                }
            }
        }

        return {
            onRequest: onRequest
        };
    });
n
Try setCurrentMatrixSublistValue instead of setSublistValue