Skip to main content
Inspiring
January 26, 2018
Answered

Refresh total amount

  • January 26, 2018
  • 2 replies
  • 1585 views

Hi,

I have a big problem with a calculation on my form or lets say it works in a strange way.

Well, I guess it had to do with the order they are calculated.

There are two fields (date) and one field (number) which calculates the difference of the two date fields as days.

E.g.

Field 1: 2018.01.26

Field 2: 2018.01.28

Field 3: 2

Field 4: 70€

That works correctly and they are updated immediatly when I'll change the date values. So far so good.

Then I've created 5 more fields format is number.

Where I can put more values into it to create a SubTotal.

The Subtotal would look like this:

140€ (which is 2x 70€ for the example above)

The SubTotal is created like

Sum1+Sum2+Sum3+Sum4+Sum5

Then I've also a Checkbox (Discount Yes/No) default to No.

When checked I display another Field where you can put a value into which will be substracted from the SubTotal field.

Now the Problem for the SubTotal field in the calculation event I placed the following:

Sum1, Sum2, Sum3, Sum4, Sum5

This works for the very first time but when I'll late change one of the date fields SubTotal isn't calculated anymore. Now the strange thing if I'll click the Discount checkbox 2 times the value for SubTotal is calculated correctly (I know that sounds a bit confusing at all.)

So my question would be ignoring the fact of possible wrong order for the calculation of the fields is there a way lets say a refresh I could send to the whole form to get the correct calculation? Well, or in other words what event happens when I check / uncheck the Discount checkbox because then it works? So maybe I can do the same from code to refresh the form.

This topic has been closed for replies.
Correct answer try67

Because each time you change the value of any field in the file it triggers the calculations of all fields, and the second time you do it the fields already have their correct values, so the result is correct.

Why not change the calculation order? That's the best approach and it will not affect anything else in the file. Any other solution is problematic.

2 replies

AirManAuthor
Inspiring
January 26, 2018

Yes that make sense to me.

try67
Community Expert
Community Expert
January 26, 2018

Yes, you need to fix the fields calculation order. You can do it by clicking on Tools, Prepare Form and then click on "More" at the right side of the window and then on "Set Field Calculation Order".

AirManAuthor
Inspiring
January 26, 2018

So my guessing was right but that does not answer what happens when clicking the Discount checkbox 2 times.

Like I've mentioned that solves the issue but why and how? So still the question is can I do that refresh (the discount checkbox seems to make) from Javascript directly instead of changing the order?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 26, 2018

Because each time you change the value of any field in the file it triggers the calculations of all fields, and the second time you do it the fields already have their correct values, so the result is correct.

Why not change the calculation order? That's the best approach and it will not affect anything else in the file. Any other solution is problematic.