Anyone run into an issue where they are unable to ...
# suitescript
m
Anyone run into an issue where they are unable to change the price level of an item with a client script(Sales Order)? It will work on other fields, but for some reason on the debugger I can see the filed change to the desired price level and then it changes back to the original. I have also tried disabling all the scripts on the SO, but it still keeps doing it
m
Is the customer record set to use a specific price level? That could be overriding what you're setting.
m
It's blank on my test customer
b
what does the code look like
m
Copy code
/**
 *@NApiVersion 2.1
 * @NScriptType ClientScript
 */
define(['N/record', 'N/search', 'N/runtime'],
    function (record, search, runtime) {
        function fieldChanged(context) {
            var currentRecord = context.currentRecord;
            var fieldId = context.fieldId;
            var sublistName = context.sublistId;

            //if (sublistName == 'item' && fieldId !== 'price' && fieldId !== 'rate') {
            if (sublistName == 'item' && fieldId == 'item') {
                var item = currentRecord.getCurrentSublistValue({ sublistId: sublistName, fieldId: 'item' });
                var tier = currentRecord.getValue({ fieldId: 'custbody_mr_discount_account' });
                debugger;
                if (tier && item) {
                var tierData = getTier(tier);

                    let t = [];
                    search.create({
                        type: "customrecord_mr_rebate_tiers",
                        filters:
                            [
                                ["custrecord_mr_rebate_item", "anyof", item],
                                "AND",
                                ["custrecord_mr_rebate_tier_item", "anyof", tierData.custrecord_mr_dis_tier[0].value]
                            ],
                        columns:
                            [
                                "custrecord_mr_rebate_vendor_item",
                                "custrecord_mr_rebate_tier_item",
                                "custrecord_mr_rebate_amount_item",
                                "custrecord_mr_rebate_fixed",
                                "custrecord_mr_rebate_item"
                            ]
                    }).run().each(function (result) {
                        t.push({
                            id: result.id,
                            vendor: result.getValue('custrecord_mr_rebate_vendor_item'),
                            tier: result.getValue('custrecord_mr_rebate_tier_item'),
                            rebate: result.getValue('custrecord_mr_rebate_amount_item'),
                            fixed: result.getValue('custrecord_mr_rebate_fixed'),
                            item: result.getValue('custrecord_mr_rebate_item')
                        });
                        return true;
                    });

                    var itemTiers = getItemTiers();
                    let isFound = itemTiers.find(t => t.item == item);

                    if (!isFound)
                        return;

                    var priceLevel = tierData.custrecord_mr_dis_price_level[0].value;
                    var pl = currentRecord.getCurrentSublistValue({ sublistId: sublistName, fieldId: 'price' });

                    if (tier && priceLevel && item) {
                        currentRecord.setCurrentSublistValue({ sublistId: sublistName, fieldId: 'price', ignoreFieldChange: false, value: -1 });
                        //if (pl !== -1 && pl !== priceLevel) {
                        //    currentRecord.setCurrentSublistValue({ sublistId: sublistName, fieldId: 'price', ignoreFieldChange: false, value: priceLevel });
                        //}

                        debugger;
                        
                        currentRecord.setCurrentSublistValue({
                            sublistId: sublistName,
                            fieldId: 'custcol_mr_rebate_amount',
                            ignoreFieldChange: true,
                            value: parseFloat(t[0].rebate)
                        });
                    }
                }
            }
            return true;
        }

        function getItemTiers() {
            var data = [];
            search.create({
                type: "customrecord_mr_rebate_tiers",
                filters:
                    [
                        ["isinactive", "is", "F"]
                    ],
                columns:
                    [
                        "custrecord_mr_rebate_vendor_item",
                        "custrecord_mr_rebate_tier_item",
                        "custrecord_mr_rebate_amount_item",
                        "custrecord_mr_rebate_fixed",
                        "custrecord_mr_rebate_item"
                    ]
            }).run().each(function (result) {
                data.push({
                    id: result.id,
                    vendor: result.getValue('custrecord_mr_rebate_vendor_item'),
                    tier: result.getValue('custrecord_mr_rebate_tier_item'),
                    rebate: result.getValue('custrecord_mr_rebate_amount_item'),
                    fixed: result.getValue('custrecord_mr_rebate_fixed'),
                    item: result.getValue('custrecord_mr_rebate_item')
                });
                return true;
            });
            return data;
        }

        function getTier(id) {
            var tierLookup = search.lookupFields({
                type: 'customrecord_mr_cus_discount_no',
                id: id,
                columns: ['custrecordcustrecord_dis_cus_no', 'custrecord_mr_cus_dis_exp_date', 'custrecord_mr_dis_price_level', 'custrecord_mr_dis_tier']
            });
            return tierLookup;
        }

        return {
            fieldChanged: fieldChanged,
        };
    });
b
setting the item field sources in the price level field, which will overwrite the changes you make
use postSourcing instead
m
Already tried, didn't work. The odd thing is, on my firefox browser it works no problem, but on chrome or other computers it is not working
b
what did the postSourcing attempt look like
m
Was not changing the price level, I can get it to change the location field no problem, but not sure what's going on with with the price level changing back. I can get it to work after save, but the sales team don't trust is and they are looking for the prices to be updated when they add the item.
The process is, select a discount account(some customers have them) for the customer on SO, then select items will get discounted when they add them on the line level. The script is supposed to change the price level and apply the rebate amount.
I posted a pic of the customization above and the fields
b
attempt above is not an attempt at using postSourcing