- 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
‎08-20-2020 07:12 AM
Hope this gives some insights:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 07:16 AM
One of my colleague did use the this.NOW and it works to trigger the calculation when the variable changes.
- 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
‎08-20-2020 07:49 AM
Thank you Willem, this looks like a neat idea. I didn't know we could make references like 'parent.g_form...'. I will try this out and let you know how it goes.