```function fieldChanged(context){ try { ...
# suitescript
b
Copy code
function fieldChanged(context){
        try {
            let form = currentRecord.get();
            if(context.fieldId == "custpage_price" || context.fieldId == "custpage_amount"){
                let Price = form.getValue('custpage_price');
                let Amount = form.getValue('custpage_amount');
                
                if(!isNull(Amount) && !isNull(Price)){                
                    let cnt = form.getLineCount('custpage_fee_lines');
                    let total = 0;
                    for(let i=0;i<cnt;i++){
                        form.selectLine({
                            sublistId: 'custpage_fee_lines',
                            line: i
                        });
    
                        let rate = form.getSublistValue({
                            sublistId: 'custpage_fee_lines',
                            fieldId: 'custcol_fee_rate',
                            line: i
                        });
                                            
                        form.setCurrentSublistValue({
                            sublistId: 'custpage_fee_lines',
                            fieldId: 'custcol_fee_calced',
                            line: i,
                            value: rate * Amount * Price                            
                        })

                        total += rate * Amount * Price;
                    }

                    form.setValue('custpage_price_per_gallon', total / Amount);
                    form.setValue('custpage_total_with_tax', total);
                }
                
            }
        } catch (error) {
            alert(error);
        }        
    }