In SuiteScript 2.0, client scripts offer flexibility in managing sublist fields, including restricting or removing values based on specific conditions. The following code snippet demonstrates how to prevent data entry in the Sublist field by clearing any entered value if the row index is even.
In this scenario, if a user attempts to enter a value in the field on an even-numbered line, the code will clear it, ensuring the field remains empty.
if (sublistId === sublist && fieldId === ‘field’) {
console.log(‘Clearing value’);
// Get the current line index within the sublist
let currentLine = currentRecord.getCurrentSublistIndex({ sublistId:sublist });
// Check if the line index is even
if (currentLine % 2 === 0) {
console.log(‘Even line detected, clearing value’);
// Clear the value of ‘ field
currentRecord.setCurrentSublistValue({
sublistId: “sublist”,
fieldId: “field”,
value: “”,
ignoreFieldChange: true // Ensures no additional field changes or triggers
});
}
}