Record Producer: How to calculate grand total from multi row variable set as it changes

Michael Gedzelm
Tera Contributor

Hi all. On my record producer, I have a multi row variable set for expense items. Each expense item has a total for that row. What I would like to do is add a Grand Total to the form which sums up all the totals for each expense item, and changes each time an expense item is added, deleted, or modified. For example, if one item (Coffee) is $40.80 and another item (Donuts) is $45.00, then the grand total on the form would be $85.80. If I click the X to remove Donuts, then the grand total would recalculate to $40.80. I have put some code in the onSubmit of the variable set, but it has no visibility to other rows of the variable set, so I can't calculate anything. How do I access all of the rows of the multi row variable set when a change is made? Thanks for your assistance.

 

MichaelGedzelm_0-1691768745197.png

 

1 ACCEPTED SOLUTION
4 REPLIES 4

Thank you Brad.  This worked with one caveat.  The line of code to set the variable (i.e. 

g_form.setValue('count',parseInt(sum));

does not work.  I was unsuccessful using this technique to set a record producer variable from a widget, and from my googling, so were many others.  Instead, I did the following:

Replace the code above with:  c.data.count = parseInt(sum)

Put the following into the Body HTML Template of the widget:  

<div>
 <input type="text" value ={{c.data.count}} readonly>
</div>

 

Hi Michael, the whole script I have tried in widget and tagged the widget to the catalog item, still it doesn't work for me. Can you please write here all the steps in detail what worked for you.

 Thank you in advance. 

Regards

Smita

 

Hi Smita, Were you able to figure out the issue? Even for me this seems to be not working, the Sum keeps posting as NaN, 

 

Could you please let me know? Thanks in advance

 

venkateshr95_0-1741004540852.png