10 Replies Latest reply on Jan 29, 2018 6:39 PM by philip gore

    Refresh total amount



      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.



      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



      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.

        • 1. Re: Refresh total amount
          try67 MVP & Adobe Community Professional

          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".

          • 2. Re: Refresh total amount
            AirMan Level 1

            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?

            • 3. Re: Refresh total amount
              try67 MVP & Adobe Community Professional

              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.

              1 person found this helpful
              • 4. Re: Refresh total amount
                AirMan Level 1

                Well let's say I'm just curious how I could solve that with javascript. On the other hands because there are a lot of fields and changing the order of all would take awhile.


                Would love to see this trigger in javascript if possible just for my reference?

                • 5. Re: Refresh total amount
                  try67 MVP & Adobe Community Professional

                  Each field has a calcOrderIndex property. You can use a script to set the order of all the fields by setting this value.

                  • 6. Re: Refresh total amount
                    gkaiseril MVP & Adobe Community Professional

                    One can place a custom calculation in the field one wants calculated last that performs all the calculations and set the resulting field values in the order one wants the calculation performed and there is not issue with the order in which Acrobat adds fields to the calculation order.


                    It is also possible to highlight multiple field names in the Set Calculation Order window and move them up or down as a group.

                    • 7. Re: Refresh total amount
                      AirMan Level 1

                      Ok I'll see I was hoping for something like this.refresh....... to refresh the whole form at once.

                      No problem I've changed the order now works as suggested.

                      • 8. Re: Refresh total amount
                        Joel_Geraci Adobe Community Professional

                        There is the Doc.calculateNow() method that forces calculation but that won't help if the calculation order is off. But honestly, the more calculated fields you have, the more it makes sense to remove the calculations from the fields themselves and consolidate all of the calculations into a single, hidden, field that updates everything... much easier to manage.

                        • 9. Re: Refresh total amount
                          AirMan Level 1

                          Yes that make sense to me.

                          • 10. Re: Refresh total amount
                            philip gore

                            Thanks a bunch! I'm really thankful.