Skip to content

Commit 9e0ec0c

Browse files
authored
Update mrvs_total_sum.js to use getRow method
1 parent 32a9954 commit 9e0ec0c

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
(function executeRule(current, previous /*null when async*/) {
2-
1+
(function executeRule(current, previous /*null when async*/ ) {
32
// --- Configuration ---
4-
var VARIABLE_NAME_TO_POPULATE_WITH_SUM = 'total_estimate'; // Add the name of your variable where total should be saved
5-
var MRVS_INTERNAL_NAME = 'item_details'; // Add the internal name of your multi-row variable set
6-
var MRVS_VARIABLE_NAME_TO_SUM = 'quoted_price'; // Add the variable name that contains the value to be added for each row
3+
var VARIABLE_NAME_TO_POPULATE_WITH_SUM = 'total_estimate'; // Variable to store the total
4+
var MRVS_INTERNAL_NAME = 'item_details'; // Internal name of your multi-row variable set
5+
var MRVS_VARIABLE_NAME_TO_SUM = 'quoted_price'; // Variable name containing the value to sum
6+
7+
// --- Don't change below ---
8+
var total_value = 0;
79

8-
// -- Don't change below --
10+
// Get the MRVS object
911
var mrvs = current.variables[MRVS_INTERNAL_NAME];
1012

11-
var total_value = 0;
12-
13-
// The mrvs variable is already a JSON string, so we need to parse it
14-
var mrvsRows = JSON.parse(mrvs);
13+
// Get the number of rows
14+
var rowCount = mrvs.getRowCount();
1515

1616
// Loop through the parsed array of rows
17-
for (var i = 0; i < mrvsRows.length; i++) {
18-
var row = mrvsRows[i];
19-
var line_price = parseFloat(row[MRVS_VARIABLE_NAME_TO_SUM]) || 0;
20-
total_value += line_price;
17+
for (var i = 0; i < rowCount; i++) {
18+
var row = mrvs.getRow(i);
19+
var line_price = parseFloat(row[MRVS_VARIABLE_NAME_TO_SUM]) || 0;
20+
total_value += line_price;
2121
}
2222

23-
2423
current.variables[VARIABLE_NAME_TO_POPULATE_WITH_SUM] = total_value.toFixed(2);
2524

26-
2725
})(current, previous);

0 commit comments

Comments
 (0)