Live Field Validation for Line Items Table
Purpose
This script enforces data completeness in a specific column of the Line Items table within a GlobalSearch document. It ensures that every row in the table contains a value in the designated column (column index 2, which corresponds to the Description field). If any row is missing data in that column, the script dynamically sets a control field (Table Control) to required, effectively blocking save operations until the issue is resolved.
How It Works
The script runs every 500 milliseconds using
setInterval.It retrieves the raw data from the Line Items table via
$$inject.tableFields['Line Items'].$$rawData().It checks each row’s value at index
2(assuming 1-based indexing).If any row has an empty string (
'') in that column:The
Table Controlfield is cleared ("").Its
requiredproperty is set totrue, preventing the document from being saved.
If all rows have valid data:
The
requiredflag onTable Controlis removed (false), allowing the document to be saved.
Key Assumptions
Column index
2corresponds to the Description field.The
Table Controlfield is used as a blocking mechanism — when marked required, it prevents save operations.The script is designed to run continuously and react in near real-time to user edits.
Code Behavior Summary
setInterval(() => {
// Check if any row in column 2 is empty
var isEmpty = false;
var data = $$inject.tableFields['Line Items'].$$rawData();
data.forEach(row => {
if (row[2] == '') {
isEmpty = true;
}
});
// If any row is empty, block save by making Table Control required
if (isEmpty) {
$$inject.fields['Table Control'] = "";
if (!$$inject.fieldProperties['Table Control'].required) {
$$inject.fieldProperties['Table Control'].required = true;
}
}
// If all rows are filled, remove the required flag
else if ($$inject.fieldProperties['Table Control'].required) {
$$inject.fieldProperties['Table Control'].required = false;
}
}, 500);
✅ Benefits
Prevents incomplete submissions by enforcing field-level validation.
Provides real-time feedback without requiring manual triggers.
Integrates seamlessly with GlobalSearch’s Live Field architecture.