Auto-Replicate Column Value in Grid - Merciglobal Cloud ERP
Overview
This guide outlines a script that automates the replication of a column value entered in the first row of a grid to all subsequent rows where a specific condition (e.g., UOM
is filled) is met. This is particularly helpful in transaction data entry scenarios within Merciglobal Cloud ERP.
Purpose
To reduce manual data entry and enhance consistency, especially when a common value like rate
is used across multiple rows in a grid.
Use Case
During data entry in modules such as purchase orders, invoices, or stock issues, it is common to apply the same rate
to all rows. This logic ensures that once a rate is entered in the first row, it is auto-populated to all rows where the UOM
(Unit of Measurement) field is filled.
JavaScript Implementation
Add the following code to your moduleβs Post Validation event for the respective column:
function trn_yarnschlg_rate_postvalid(hotrow, hotcol, colname, oldval, newval) {
let value = parseFloat(eval(newval));
if (value > 0 && hotrow == 0) {
// Apply only for the first row
for (var z = 1; z < hot.count(); z++) {
let uom = hot.getValue(z, "uom");
if (!uom) break; // Stop when empty row is encountered
hot.setValue(z, hotcol, value); // Set rate for subsequent rows
}
}
}
How It Works
- Trigger Condition: Activated when a non-zero rate is entered in the first row (
hotrow == 0
). -
Loop Execution:
-
Starts from the second row onward.
- Checks if the
UOM
is filled. - If
UOM
exists, replicates therate
from the first row. - If
UOM
is empty, the loop stops assuming data entry ends there.
Key Benefits
- Prevents unintentional overwriting of empty rows.
- Enhances data consistency across the grid.
- Improves user efficiency during high-volume data entry tasks.
Notes
- Ensure this script is included in the correct post-validation event specific to the column you want to auto-replicate.
- Adapt field names (
rate
,uom
) to match your moduleβs field definitions.
Author
Merci Development Team Think Simple π
Explore more developer tips at the Merciglobal Cloud ERP Documentation