In NetSuite, when using a LIST-type sublist in a Suitelet, setting a field as disabled prevents updates even from scripts like setSublistValue. However, there are cases where you want a field to appear read-only to the user but still update it via script.
Here’s a simple JavaScript function that makes a specific sublist field read-only using jQuery, without breaking NetSuite’s data binding.
Use Case
You want to:
- Prevent user edits to a currency/text field in a sublist.
- Keep the field updatable via script.
- Apply the change client-side, without altering server-side display types.
Solution
/**
* Disables the "New Allocation Amount" field in the sublist to prevent user edits.
* Applies readonly, removes tab focus, and updates background for visual cue.
*
* @returns {void}
*/
function disableNewAllocAmtField() {
try {
const fieldId = UI_PAGE_FIELDS.SL_NEW_ALLOC_AMT.id; // e.g., "custpage_new_allocation_amt"
const selector = `input[name^='${fieldId}'][name$='formattedValue']`;
jQuery(selector).each(function () {
jQuery(this)
.attr('readonly', true)
.attr('tabindex', '-1')
.css('background-color', '#fafafaff'); // Optional: visual cue
});
} catch (e) {
console.error("Error on disableNewAllocAmtField", e.message);
}
}
How It Works
input[name^='custpage_new_allocation_amt'][name$='formattedValue']matches all input fields rendered for the formatted display of the field in the sublist.readonlymakes the input uneditable.tabindex="-1"removes the field from tab order.- The light gray background (
#f4f4f4f6) gives a visual cue that it’s read-only.
Where to Call It
You should call disableNewAllocAmtField() inside:
pageInit(context)– when the Suitelet page loads.lineInit(context)– if the sublist redraws when a line is selected or added.
Can Use .prop('disabled', true)
You can use:
jQuery("input[name^='custpage_fieldid_']").prop('disabled', true);
Result
- Your field is visually and functionally read-only.
- You can still update it using
setSublistValue()orsetCurrentSublistValue()from scripts.