michoel
09/12/2017, 11:20 PM/**
* This function attempts to disable an item sublist field through SuiteScript API, and disables the field
* through the DOM if that fails.
*
* @param rec {N/currentRecord.CurrentRecord}
* @param fieldId {String} Internal id of a column field
* @return {void}
*/
function disableSublistField(rec, fieldId) {
/* {Number} The current item index */
var line = rec.getCurrentSublistIndex({sublistId: 'item'});
try {
/* {N/record.Field} */
var field = rec.getSublistField({sublistId: 'item', fieldId: fieldId, line: line});
field.isDisabled = true;
} catch (e) {
/*
* The getSublistField method will throw an error if the line has not yet been committed, so we have
* to disable the field through the DOM and let a validateField function guard it from edit.
*/
jQuery("input[name=inpt_" + fieldId + "]").prop('disabled', true); //For select fields
jQuery("input[name=" + fieldId + "_formattedValue]").prop('disabled', true); // For text/number fields
}
}