- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 07:03 AM
Hello all,
I have a catalog item that includes a multi-row variable set. I've just read this handy little article about how to access the content of rows that have been added:
What I want to do is trigger a client script on the catalog item itself (not the variable set) to update another variable on the catalog item. Specifically, it will total up the figures in one column of the multi-row variable set. But I can't see how to trigger this when a row is added. I know that on submit client scripts are not available to multi-row variable sets, but in any case I think the client script would need to run at the level of the catalog item itself.
Here's a screenshot to clarify...
So, as a row is added, I want to update the variable at the bottom, 'Total Cost (£ / Euro)' to be the sum of the figures in the final column on each row in the variable set, 'Cost Per Item (£ / Euro)'. I'm able to access the values OK in a client script - my dilemna is all about how to trigger the rule.
Any thoughts?
Thank you.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 07:26 AM
I am thinking of a two fold solution.
The trigger should be on the Multi Row Variable Set. Because that is changing. Something like this, onChange on for example total cost in the MRVS:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(parent.g_form){
parent.g_form.setValue('trigger_calculation', true);
}
}
The trigger_calculation is a new Variable on the Catalog item. On the Catalog Item we can then have an onChange on the trigger_calculation field like so:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//get the MRVS
var multiRowVariableSet = JSON.parse(g_form.getValue('variable_set_1'));
var totalCost = 0
for (var i = 0; i < multiRowVariableSet.length; i++) {
totalCost += multiRowVariableSet[i].totalCostVariableInMRVS;//add all totals from the MRVS to 1 total
}
}
g_form.setValue("trigger_calculation", false);//reset the trigger
g_form.setValue("totalCostOnCatalogItem");//set the total
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2022 04:39 AM
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2022 07:05 AM
can you share me script include.
scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 07:28 AM
Please also have a peak of inspiration on this article I wrote:
Any feedback on it is much appreciated! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 08:49 AM
I took a look at your article too. Very informative - I am sure I will come across use cases where I'll fall back on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2021 07:35 PM
You can run a onload client script and use setInterval so that every 3 sec it will calculate :
function onLoad() {
setInterval(function(){
var multiRowVariableSet = JSON.parse(g_form.getValue('MVST internal name'));
var totalCost = 0;
for (var i = 0; i < multiRowVariableSet.length; i++) {
totalCost = parseInt(totalCost) + parseInt(multiRowVariableSet[i].totalCostvariable);
//alert(totalCost);
}
g_form.setValue("estimated_grand_total",totalCost);
}, 3000);
}