I need help populating a variable from Multi Row Variable Set

AM24
Giga Guru

Heilo, say I have a multi row variable set in a record producer that has two fields, description and percentage. So for example,

Description 1      |          75%

Description 2      |         5%

 

I have a variable outside the mrvs called total percentage. I want that variable to take the sum of the percentages of in the multi row variable set, when a new row is submitted. So for this example, when Description 2 is submitted, the total percentage is updated to 80%.

I want this to apply to my record producer as well, as I will be able to edit the mrvs from the variable editor in the record producer. I had tried to use an onSubmit client script within the mrvs, but that causes errors in the record producer.

I was wondering if you had suggestions. Thank you.

2 REPLIES 2

Allen Andreas
Administrator
Administrator

Hi,

You can use an onChange client script, on the MVRS, and the percentage field with script such as:

var cTot = parent.g_form.getValue('total'); //replace total with your variable that contains total
var cVal = newValue;
parent.g_form.setValue('total', Number(cTot) + Number(cVal)); //replace total with your variable that contains total

So this would take a setup like this:

find_real_file.png

And as you add rows to your MVRS, it'll add them together in the total, like so:

find_real_file.png

If the set your onChange client script to also work on the target record (it's a checkbox on the form you need to check), then it'll work there too:

find_real_file.png

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi AM,

If I remember correctly, onChange() script won't get executed when the row is deleted in mrvs and the total on the form will not get updated and will be incorrect.

AFAIK, the only viable solution that works correctly is to create a button on the form to update the total field when pressed.