5 Replies Latest reply: May 24, 2012 12:39 AM by Niall O'Donovan RSS

    Error Handling (How To?)

    kdjeter Community Member

      Hello,

       

      I have a removeInstance tied to a button in the click event.  I know this will generate a default Adobe error if the minimum number of rows have been reached.

       

      I would like to replace the default Adobe error of "index out of bounds" with a more user friendly error message.

       

      I tried this after the removeInstance, but default error still popped-up:

      xfa.host.messageBox("Delete error encountered.  Maximum number of rows deleted.", "Warning",1,0)

       

      Can someone offer assistance?

       

      Thanks

        • 1. Re: Error Handling (How To?)
          kdjeter Community Member

          How to simply handle errors in a click event?  I think this is an easy answer, but I am new to FormCalc/Java Script.  I simply want to replace default Adobe error with mine.

           

          Any assistance would be greatly appreciated.

           

          Thanks!

          • 2. Re: Error Handling (How To?)
            Niall O'Donovan Community Member

            Hi,

             

            You could wrap your removeInstance script in an if statement that looks at the number of instances.

             

            if (Table1._Row1.count > 1) {

                 Table1._Row1.removeInstance(this.parent.index);

            }

             

            You could turn off the Acrobat debugger from automatically opening when an error is encountered (see preferences), but that wont help users.

             

            Hope that helps,

             

            Niall

            • 3. Re: Error Handling (How To?)
              kdjeter Community Member

              Ecellent Niall!  This worked like a charm.  I added an alert so the user would know what was taking place.

               

              Thanks so much for your help.  I knew this was simple.

              • 4. Re: Error Handling (How To?)
                kdjeter Community Member

                Hello,

                 

                I am now getting this error:

                Error: syntax error near token '{' on line 2, column 72

                 

                 

                Here is the code:

                 

                if (page1.subform1.TableParent.TableBodyRow.instanceManager.count > 1) {

                page1.subform1.TableParent.TableBodyRow.instanceManager.removeInstance(1)

                }

                • 5. Re: Error Handling (How To?)
                  Niall O'Donovan Community Member

                  Hi,

                   

                  The script looks reasonably in order. Can you check that the language is set to JavaScript (and not FormCalc).

                   

                  I suspect the relative references could be shortened. It just depends on where the button is relative to the repeating row.

                   

                  Just to note in my previous script the underscore (_) in front of the repeating object name is shorthand for instanceManager. So _TableBodyRow.removeInstance(this.parent.index) should work.

                   

                  Also, the parameter for the removeInstance() method is the instance number that you want to remove - based on a zero numbering system. So your script will always look to remove the second row. You probably don't want this, so if the button is in the repeating row, passing this.parent.index as the parameter will work better.

                   

                  Hope that helps,

                   

                  Niall