- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2024 04:32 AM
Hi members,
I have a requirement to sum up the cost value (variable set) and to display it in the Total Cost variable (outside the variable set). I have found couple of similar old posts and members marked it as helpful but it didnt work at all by onchange client scipt etc...
Anyone can help me out will be thankful.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2024 07:11 AM
I put this in a Client Script and it worked for me. I assumed your Cost variable is named "cost".
var mrvsName = 'yourmrvsname';
var mrvs = g_form.getValue(mrvsName);
var total_cost = 0;
var objList = JSON.parse(mrvs); //The option values are captured as a JSON string, which we parse, creating an array
for (var i = 0; i < objList.length; i++) { //Iterate through array
var row = objList[i];
total_cost += parseInt(row.cost);
}
g_form.addInfoMessage("Total cost is " + total_cost);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2024 07:11 AM
I put this in a Client Script and it worked for me. I assumed your Cost variable is named "cost".
var mrvsName = 'yourmrvsname';
var mrvs = g_form.getValue(mrvsName);
var total_cost = 0;
var objList = JSON.parse(mrvs); //The option values are captured as a JSON string, which we parse, creating an array
for (var i = 0; i < objList.length; i++) { //Iterate through array
var row = objList[i];
total_cost += parseInt(row.cost);
}
g_form.addInfoMessage("Total cost is " + total_cost);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2024 11:02 PM
Thanks Jennifer,
Your solution helped me to achieve the required work.