16 Replies Latest reply on Apr 28, 2008 12:44 PM by Patrick Leckey

    Calculations don't work after saving

    Mark Simkiss
      I have a simple form with these fields:

      quantity:
      user entry

      price:
      if (quantity.value > 0 && quantity.value < 5000){
      event.value = quantity.value * 0.448;
      }

      if (quantity.value > 4999 && quantity.value < 10000){
      event.value = quantity.value * 0.281;
      }

      if (quantity.value > 9999){
      event.value = quantity.value * 0.189;
      }

      fee:
      (user entry)

      tax:
      var price = this.getField("price");
      var fee = this.getField("fee");
      event.value = (price.value + fee.value) * 0.06;

      total:
      sum of price, fee, and tax

      ==============
      The form works fine while editing it and switching to Preview mode, but once I save it then open it, it no longer works. What am I missing here?
        • 1. Re: Calculations don't work after saving
          Patrick Leckey Level 3
          Assuming you're talking about LiveCycle Designer (since you mention Preview mode), you are probably saving the form as a Static PDF.

          Open your form in Designer, choose "File > Save As ..." and in the "Save as type:" dropdown box (under the file name), choose "Adobe Dynamic XML Form" instead of "Adobe Static PDF Form".

          You can change this to your default file type by choosing "Tools > Options ..." and under the "Document Handling" section setting the "Default File Type For New Forms" dropdown to "Dynamic XML Form".
          • 2. Re: Calculations don't work after saving
            Mark Simkiss Level 1
            I'm acutally using Acrobat 8 Professional. I'm not using LiveCycle. Anything in A8P that could trigger the same thing?
            • 3. Re: Calculations don't work after saving
              Patrick Leckey Level 3
              Then what "preview" mode are you talking about?

              You know that in Acrobat 8 Professional when you choose "Forms > Create New Form" that actually opens LiveCycle Designer, right?
              • 4. Re: Calculations don't work after saving
                Mark Simkiss Level 1
                here's the flow...
                open a8p
                open static pdf form
                tools > forms > show forms toolbar
                click edit layout on forms toolbar

                it's then that i'm editing the "input boxes" and creating the formulas. at no time does it show or switch to anything LiveCycle (unless I'm blind, but I only have a8p unless it's interwoven into a8p).

                on the forms toolbar, you have an edit layout button and a preview button.

                i also have a client who downloaded the trial version of a8p and i sent her the following instructions, which work perfectly for her too, until she saves and reopens, then they stop working... (also, when I SAVE AS, there is no Adobe Dynamic XML option)...

                -------------
                1. Open PDF you want

                2. Open Forms toolbar if not already open by:

                a. Tools > Forms > Show Forms Toolbar

                3. On Forms toolbar, click Edit Layout

                4. Right-Click on the Quantity Ordered box, e.g., and it will turn red

                a. Select Properties from the pop-up menu

                5. In the General tab, change the name to quantity

                a. You can leave the tooltip as whatever you want

                6. Repeat this for all boxes that are part of a calculation

                a. For the calculations to work, Name under the General tab must be a single word

                i. Change quantity ordered to quantity and rename other boxes too

                1. Use: price, fee, tax, and total (these are the Names I selected for the formulas to work)

                7. Now pull up the properties for each of these boxes, but click on the Calculate tab this time

                8. Select Custom calculation script:, then hit the Edit button

                For the price box, copy and paste in this formula:

                if (quantity.value > 0 && quantity.value < 5000){

                event.value = quantity.value * 0.448;

                }

                if (quantity.value > 4999 && quantity.value < 10000){

                event.value = quantity.value * 0.281;

                }

                if (quantity.value > 9999){

                event.value = quantity.value * 0.189;

                }



                For the tax box, copy and paste in this formula:

                var price = this.getField("price");
                var fee = this.getField("fee");
                event.value = (price.value + fee.value) * 0.06;



                For the total box, instead of clicking on Custom calculation script:, click on Value is the [ sum (+) ] and then check the boxes for price, fee, and tax.

                For quantity, theres no calculation.
                For fee, theres no calculation.

                If you want to change the price points or anything for that matter, just change the numbers in the formula.

                Price brackets are in red, cost per unit in dollars in blue, and PA tax rate in purple.
                • 5. Re: Calculations don't work after saving
                  Bernd Alheit Adobe Community Professional & MVP
                  Where did you assign a value to variable 'quantity' ?
                  • 6. Re: Calculations don't work after saving
                    Mark Simkiss Level 1
                    it's assigned as the tag for the input box under the general tab when editing.

                    here's the PDF if you want to open it. there are only 5 fields. it's very simple...

                    http://www.simkiss.net/pdf/smarttech.pdf
                    • 7. Re: Calculations don't work after saving
                      (Aandi_Inston) Level 1
                      Sounds as if you aren't using getValue to associate a JavaScript
                      variable with a form field. The absence of this is probably what led
                      everyone to think you had a Designer form.

                      Aandi Inston
                      • 8. Re: Calculations don't work after saving
                        Mark Simkiss Level 1
                        I am an Actionscript programmer, not a Javascript programmer and while they're very similar, I'm frustrated because if it were Actionscript, I could make it work in 60 seconds. This is my very first attempt at anything Javascript or anything dynamic for a PDF. Flash is my baby.

                        Could someone please be so kind as to paste the very simple code that I put into these 5 fields' script boxes, pretty please with a cherry on top?

                        I know I'm missing something really stupid here.

                        http://www.simkiss.net/pdf/smarttech.pdf
                        • 9. Re: Calculations don't work after saving
                          (Aandi_Inston) Level 1
                          Vitually every example of JavaScript form programming should be
                          showing the use of getField...

                          Aandi Inston
                          • 10. Re: Calculations don't work after saving
                            Bernd Alheit Adobe Community Professional & MVP
                            You are using:

                            var price = this.getField("price");

                            var fee = this.getField("fee");

                            do the same for field 'quantity', like:

                            var quantity = this.getField("quantity");
                            • 11. Re: Calculations don't work after saving
                              Mark Simkiss Level 1
                              sweet! that worked, so now it properly calculates price, but in doing so (adding var quantity = this.getField("quantity");), and only that, now tax doesn't calculate. how bizarre! how can this be? i'm stupified! it's like there's a limit to the number of calculations you can make.
                              • 12. Re: Calculations don't work after saving
                                Mark Simkiss Level 1
                                okay, i highlighted the script for tax, cut it, closed it, opened it again, pasted it back in, closed it, and now it works.

                                are we onto a bug in a8p here?
                                • 13. Re: Calculations don't work after saving
                                  Mark Simkiss Level 1
                                  If I use a script for total instead of using the built-in sum function I was using, everything works fine. Seems that they don't play well together for me.
                                  • 14. Re: Calculations don't work after saving
                                    Mark Simkiss Level 1
                                    that was it.

                                    i'm not able to use the built-in sum function in combination with custome scripts. no big deal really, but not a bug you would expect.

                                    (if indeed this bug can be replicated and it's not just my system)
                                    • 15. Re: Calculations don't work after saving
                                      Going back to the March 3rd post. I am working in Acrobat Professional 8 and when I attempt to edit my form, it opens in LiveCycle Designer. Now I try to save it as the dynamic and my only option is static 7 or 8. I went to Tools/Options and chose my default file type as Acrobat 8 Dynamic XML form and still I can't save it as such. Any suggestions.

                                      My general problem is that I can't work in Acrobat Professional as all the tutorials show. I am in this LiveCycle and can't figure out how to make a calculated field. When I make the field numeric, I can make it calculated read only, but then can't choose the fields to add together to make it total. Make any sense? Any way I can work in Professional on this form and override working in LiveCycle? Thanks for any advice.
                                      • 16. Re: Calculations don't work after saving
                                        Patrick Leckey Level 3
                                        If your form was created in Acrobat, you can only save it as a static form. Only XFA forms can be dynamic, and Acrobat cannot create XFA forms. Only LiveCycle Designer can.

                                        I can understand how this may seem confusing, but please understand it is not the application editing the PDF, but the one that *CREATED* it. If you, in Acrobat, went to the Create PDF menu and created the PDF in Acrobat, it will only be a static form.

                                        You need to load LiveCycle Designer separately from Acrobat (it's in your start menu, right under Acrobat Professional) and create your PDF from scratch in LiveCycle Designer in order for it to be saved as a dynamic PDF.

                                        If you are attempting to add calculation and other events to AcroForm fields, you will not be able to do this from within LiveCycle Designer. Instead of going into Designer, just choose the hand tool, right click on the field and choose "Properties", then go to the "Actions" tab.

                                        You can add legacy AcroForm fields to a static PDF document by choosing your form tool from the "Tools > Forms" menu (button, list box, etc). If your workflow requires a dynamic form, you have no choice but to use LiveCycle Designer.