For the following script, I can disable lines 2 on...
# suitescript
v
For the following script, I can disable lines 2 onwards but the first line is only disabled after it is committed I can't see where I am going wrong
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(['N/currentRecord'], function (currentRecord) {
function fieldChanged(context) {
var currentRecordObj = currentRecord.get();
var sublistId = context.sublistId;
var fieldId = context.fieldId;
log.debug({
title: 'Sublist ID',
details: sublistId
});
log.debug({
title: 'Field ID',
details: fieldId
});
var lineNumber=currentRecordObj.getCurrentSublistIndex({
sublistId: 'item'
})
log.debug('lineNumber',lineNumber)
var lineItem = currentRecordObj.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'item'
});
// Check if the sublist is "item" and the field changed is "item"
if (sublistId === 'item' && lineNumber !== -1) {
log.debug({
title: 'Line',
details: lineNumber
});
var item = currentRecordObj.getCurrentSublistValue({
sublistId: 'item',
fieldId: fieldId
});
log.debug({
title: 'Item',
details: item
});
// Check if an item is selected in the line
if (item) {
currentRecordObj.getCurrentSublistValue({
sublistId:'item',
fieldId:'price'
}).isDisabled=true
log.debug('disabledField','disabled field with getcurrentsublistvalue')
// Disable the "rate" field for the selected line
currentRecordObj.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
line: lineNumber,
value:'',
ignoreFieldChange: true
}).isDisabled=true;
log.debug('Rate field disabled for line ' + lineNumber);
} else {
// Enable the "rate" field for the selected line
currentRecordObj.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
line:lineNumber,
value:'',
ignoreFieldChange: true
}).isDisabled=true
log.debug('Rate field enabled for line ' + lineNumber);
}
}
}
return {
fieldChanged: fieldChanged
};
});
b
your code shouldnt disable fields at all, there is no usage of Column.isDisabled nor Field.isDisabled