Trying to clear out price sublist data on copy of ...
# suitescript
j
Trying to clear out price sublist data on copy of an Inventory part. Script not clearing out data from "copied" item. Any thoughts are appreciated.
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define(['N/currentRecord'], function(currentRecord) {

    /**
     * Executes when the page is initialized.
     * @param {Object} context - Script execution context
     * @param {Record} context.currentRecord - Current form record
     * @param {string} context.mode - Mode in which the form is loaded (create, copy, edit, etc.)
     */
    function pageInit(context) {
        var rec = context.currentRecord;

        // Check if the form is in "copy" mode
        if (context.mode === 'copy') {
            var lineCount = rec.getLineCount({ sublistId: 'price1' });

            // Iterate through the Price Levels sublist and clear the price field
            for (var i = 0; i < lineCount; i++) {
                rec.selectLine({ sublistId: 'price1', line: i });
                rec.setCurrentSublistValue({
                    sublistId: 'price1',
                    fieldId: 'price',
                    value: 0 // Clear pricing by setting it to 0
                });
                rec.commitLine({ sublistId: 'price1' });
            }
        }
    }

    return {
        pageInit: pageInit
    };
});
b
j
That worked! Thanks.