- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 06:22 AM
Is there a way to calculate the total for this? The quantity will still need to be multiplied based on the price per size of the drink and I wanted to store the total into another variable that is not inside the multi-row variable set.
Is there also a way so that every time they click add It'll update the total variable outside of the MRVS
Solved! Go to Solution.
- Labels:
-
Studio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2022 02:34 AM
Thread closed:
Please refer to this link for displaying the data: How to display data from a client script to an HTML widget and display its value in a text field.
In short, for the calculation and displaying of data. I used a custom with label variable and created a widget
with the following client script:
api.controller = function($scope) {
/* widget controller */
var c = this;
$scope.$watch(function() {
//Internal Name of Variable Set 'item_details'
return $scope.page.g_form.getValue('choose_your_drink_s');
}, function(value) {
if (value) {
var mrvsData = JSON.parse(value.replace(/'/g, ''));
console.log(value);
var totalCost = 0;
for (var i = 0; i < mrvsData.length; i++) {
var mrvs = mrvsData[i];
totalCost += parseFloat(mrvs.pricePerSize) * parseFloat(mrvs.quantity);
alert('Calculating: ' + totalCost + ' for --> ' + mrvs.pricePerSize);
}
//Set Value in the Total Cost
alert(totalCost);
c.data.cost = totalCost;
$scope.page.g_form.setValue('total_amount',totalCost);
alert(c.data.cost);
}
});
};
and HTML:
<div>
<input type="text" value ={{c.data.cost}} readonly>
</div>
To achieve this:
~Melvin B.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 07:14 AM
Hi,
Please refer to this link you may have to change script a little as per your choice.
Calculating totals from mult-row variable set rows in to a variable on a record producer?
Mark Correct or Helpful if it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 07:42 AM
Hello Yousaf,
There seems to be only one variable being calculated. How can I parse two variables? Since the quantity will still need to be multiplied based on the price per size of the drink and will it be an onChange script? Where will I apply the script?
edit:
I have tried but I cannot seem to make it work..
Here is my config and script:
I am currently getting this error
For more reference, here is the config for the mrvs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 08:47 AM
onChange of MRVS won't work directly
check this link and you will get solution/way on detecting add/removal of row and based on that you can calculate
Add the total cost in multirow variable set
Regards
Ankur
Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 05:42 PM
Hello Ankur,
I have tried it but I cannot seem to see the field.
This is the widget alongside the script:
It is showing like this, I cannot seem to see the field but the data can be seen in the alert.
Here is the config for the variable.