7 Replies Latest reply on Nov 4, 2015 1:00 PM by kdoske

    importDataObject Error Handeling & File Renaming

    kdoske

      When I use the code below if the user selects a file to attach that is currently opened in another program Acrobat just hangs for a second and then returns a 1 saying that the file attached correctly. However, the file never actually attaches. When I use the built in attach button in the same senario Acrobat notifies the user that the file is open and must be closed before it can be added. How can I add this same functionality using importDataObject? Is there a error code list that may shed light on this or is my code not sound? Also, is it possible to change the name of the file that is attached?

       

                                      test = this.importDataObject({cName: "Authdoc"});

                                      if (test != 1){

                                                     app.alert({ cMsg: "user cancelled out/error", nIcon: 3});

                                      }

                                      else{

      app.alert({ cMsg: "Your authorization has been attached. blah blah blah", nIcon: 3});                           

        }

       

       

       

       

      Thanks guys!

        • 1. Re: importDataObject Error Handeling & File Renaming
          kdoske Level 1

          I found if I use the code below it does give the prompt letting the user know the file is in use by another application. It doesn't say to close it, but hopefully they will get the idea--probably not. Anyway, the problem with using this new method is I don't have any error code returns.

           

          app.execMenuItem("AddFileAttachment");

           

          It would probably still be better if I could use the code above and create my own popups based on the error codes received. With that in mind I'm still curious if there is an error code return list somewhere.

           

          • 2. Re: importDataObject Error Handeling & File Renaming
            try67 MVP & Adobe Community Professional

            You should compare the return code to 0. If it's anything else, there was a problem. You can then inform the user to close the file in any other application and try again.

            • 3. Re: importDataObject Error Handeling & File Renaming
              kdoske Level 1


              The problem though is that when I use importDataObject and the user selects a file that is open in a nother program importdatobject will return a 1/true even though nothing actually attaches. If I use the app.execMenuItem("AddFileAttachment") it returns nothing in any senario. So the first senario is good because I can create actions for other fields if the user clicks the cancel button in the browser dialog but its bad becaue it gives false positives if they select an open file. The second senario is good because it notifies them they selected an open file but if they click the cancel button I have no way of knowing and then other fields in the form will remain in an incorrect value. I'm not sure what to do here seems like it might be an actual issue in the API. Here is the print.f I am using to get the return values.

               

              console.println("return value = " + this.importDataObject({cName: "Auth"}));

               

              oh, the menu attachment method is also bad because it gives random cNames to the files that I can't really interact with reliably. I am basically associating file attachemnts with certain checkboxes. So I need to accurately check and uncheck boxes when a form is attached for that checkbox.

              • 4. Re: importDataObject Error Handeling & File Renaming
                try67 MVP & Adobe Community Professional

                Sorry, please disregard the comment above. I got confused with another data object-related method.

                Did you try placing a try-catch clause around this command?

                • 5. Re: importDataObject Error Handeling & File Renaming
                  Test Screen Name Most Valuable Participant

                  About execMenuItem: it really is just the same as sending a click to a menu item. You cannot detect whether it "worked", intercept messages or anything else. Rarely useful, to be honest.

                  • 6. Re: importDataObject Error Handeling & File Renaming
                    try67 MVP & Adobe Community Professional

                    True, but you can sometimes detect if it worked by its effect on the file. For example, you can check whether the number of data objects before and after executing the command changed... If it's one higher afterwards, that means the user successfully added a new data object.

                    • 7. Re: importDataObject Error Handeling & File Renaming
                      kdoske Level 1

                      Thanks Try67. I havn't tried this yet but this seems like a really clever work around. I'll look at the api docs tomorrow to see how I get a return from the total data objects in the PDF. Thanks again this is really helpful.