Skip to content

Commit 32a9954

Browse files
authored
Create mrvs_total_sum.js
1 parent 8074943 commit 32a9954

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(function executeRule(current, previous /*null when async*/) {
2+
3+
// --- 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
7+
8+
// -- Don't change below --
9+
var mrvs = current.variables[MRVS_INTERNAL_NAME];
10+
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);
15+
16+
// 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;
21+
}
22+
23+
24+
current.variables[VARIABLE_NAME_TO_POPULATE_WITH_SUM] = total_value.toFixed(2);
25+
26+
27+
})(current, previous);

0 commit comments

Comments
 (0)