When editing a sublist using currentRecord.setCurr...
# suitescript
m
When editing a sublist using currentRecord.setCurrentSublistValue, do I have to save the record or commit line in suitescript 2.0? Scenario: When a user enters an item on item line, I want client script to check what subsidiary the order is in and if the item doesnt belong to that subsidiary then set the pricelevel to custom so that they can enter column rate manually. When I set pricelevel to custom, column rate is disabled because the price is expected to come item master. This behaviour doesn't happen when do in UI. So I am wonder if it is because the change on pricelevel is not persisted to the database without a save. I also tried to enable colunm rate but that is cause issues, a pop up keeps coming up saying "Please add item" My code is below:
Copy code
var nCurrentRecord = scriptContext.currentRecord;
var department = nCurrentRecord.getValue({fieldId: 'department'})
if (scriptContext.sublistId === 'item' && scriptContext.fieldId === 'item' && department) {
    var subsidiary = nCurrentRecord.getValue({fieldId: 'subsidiary'})
    var subsidiaryText = nCurrentRecord.getText({fieldId: 'subsidiary'})
    console.log({title: 'subsidiaryText', details: subsidiaryText})

    if (subsidiary === '2') {
        var price_display = nCurrentRecord.getCurrentSublistValue({sublistId: 'item', fieldId: 'price_display'});
        //console.log('price_display',price_display);
        if(price_display !== 'Custom') {
            nCurrentRecord.setCurrentSublistValue({
                sublistId: 'item',
                fieldId: 'price',
                value: '-1', //Custom
                ignoreFieldChange: true
            })
            
            // The column Rate is mandatory and is disabled for editing so needs to be enabled.
            /*var sublistObj = nCurrentRecord.getSublist({
                sublistId: 'item'
            });
            var columnObj = sublistObj.getColumn({
                fieldId: 'rate'
            });
            columnObj.isDisabled = false;

            //Commit line
            nCurrentRecord.commitLine({sublistId: 'item'})
*/
        }
    }
}
t
I think there is a limitation into what you can do on the sublist. My take instead of dynamically hiding the column why not prompt an alert when they need to populate your column
👍 1