13 Replies Latest reply on Jan 29, 2014 1:03 PM by tdjohnson7700

    Acquire data from a tab delimited file using a popup dialog object on a stamp

    tdjohnson7700

      I am trying to import data from a tab delimited file using a popup dialog object on a stamp.  I have purchased the book by Thom Parker--All About PDF Stamps in Acrobat and Paperless Workflows and have been working through the examples in the appendix.

       

      My problem is understanding how to bring the data into the dialog object from the file.

       

      I don't want to plagiarize his book--so am electing at this time not to show my code.  The  script is reading the file, just not bringing in the records from the file so that I can select which line to import into the stamp.

       

      I have typed in the code exactly how the book describes, but when the popup dialog object is selected, there is nothing in the drop-down.  When I click OK, the first record is put on the stamp--except for the fields that I am wanting to appear in the dialog object popup box.

       

      I have searched the forums, and also the JavaScript reference.  There are examples of the popup dialog object, but none of them show how to import the data from a file--just for the items to be typed in as the list.

       

      Any help would be greatly appreciated!  i have been trying to work on this for several months now.

        • 1. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
          try67 MVP & Adobe Community Professional

          It's good you don't want to post the code from the book, but this makes it very difficult to help you out with the problem... Either explain how the code is supposed to work, what you tried, and what the EXACT results were (including any error messages), or contact Thom personally (he's active on these forums, or via his website) and ask for his help directly.

          • 2. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
            tdjohnson7700 Level 1

            The question I have is that I am not understanding some of the items that are referenced in the script.

             

            I have a stamp with the appearance name of #RevByFromTab

             

            On the stamp are two fields--one is named RevByFromTab (the name of the person) and the other is EmailFromTab (for their email address.

             

            In the trusted function, he has

             

            var GetTabData = app.trustedFunction(function(cPath, oName, oEmail)

             

            my first question is--

             

            oName--is this a JavaScript field referring to a particular statement in the code or is this just another name for the RevByFromTab on the stamp--same with the oEmail in the function and the EmailFromTab on the stamp

             

            Then--in the stamp script, there is another line

             

            var oEmailFld = this.getField("EmailFromTab");

             

             

            which points to the email field.

             

            on the popup menu, when the list is referenced, it has

             

            var oList = {};

             

            for (var cName in oData)

                 oList[cName] = -1

             

            I am confused about all the different references to the oName, cName for the RevByFromTab field

             

            I have the code typed exactly how it is in the book, but when the dialog object comes up and you select the drop down arrow, there is nothing to select--what is supposed to happen is the RevByFromTab field is supposed to be displayed, you select one of the names, and on the stamp the RevByFromTab is populated from the item that was chosed and the EmailFromTab field is populated from the corresponding email address.

             

            I have other fields on the stamp that corresponds to other fields in the text file.  They are populated with the 1st record in the text file with the corresponding column names--so I know that the file is getting referenced.  However, the two fields that are in the script are not populated.

             

            If you could shed any light on this, I would greatly appreciate it.  I am fairly new to javascript, but I do understand how to set up the stamp, how to do the appearance name of the stamp, how to set up the trusted function as a javascript file, etc.  It is the referneces to the fields that I am confused about.

             

            Thank you in advance for your help.

            • 3. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
              try67 MVP & Adobe Community Professional

              It's almost impossible to attempt to answer your questions based on fragments of code, so I prefer not to try at all, as I could just be giving you advice that will cause more problems than solve...

              • 4. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
                tdjohnson7700 Level 1

                I completely understand and appreciate you trying to help.  I will keep on working on it.

                • 5. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
                  Karl Heinz Kremer Adobe Community Professional

                  Another thing you could do is to tell us which script it is in the book?

                  Which page is it on? What is it called? I have the book right here, and if

                  you can point me to the script, I might be able to provide some pointers.

                   

                   

                   

                   

                  Karl Heinz Kremer

                  • 6. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
                    tdjohnson7700 Level 1

                    Thank you so much, Karl.

                     

                    The script that I am using starts at the bottom of page 207--importing a Tab Delimited file.

                     

                    The trusted function is on page 207.

                     

                    The stamp script is on page 208--

                         the Dialog Object is from page 200.

                     

                         On the Dialog Object--I typed everything exactly as it is on page 200 except for the first line--

                              var olist = {A:-1, B:-1, c:-1};

                         which is for the first example.  I just left this line off.

                         then the rest of the script follows as shown on page 208.

                     

                    The Stamp has the appearance name of #RevByFromTab with two fields--RevByFromTab and EmailFromTab.

                     

                    The stamp script is in the calculation event of the RevByFromTab field.

                     

                    When the stamp is selected,  the dialog popup box comes on the screen, but when you click the down arrow--nothing shows up.

                     

                    When I place the stamp, the RevByFromTab field says none  and EmailFromTab field shows undefined.

                     

                    I have typed everything exactly how the scripts are shown in the book.

                     

                    Any assistance would be GREATLY appreciated!

                    • 7. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
                      Karl Heinz Kremer Adobe Community Professional

                      OK, I finally had a chance to look at the scripts. I can see three reasons

                      (assuming that there are no other errors in the script, I assume you

                      checked the JavaScript console for errors):

                       

                      1. Your trusted function is not a trusted function. Did you put this

                      function into a folder level script so that it will get executed at system

                      startup?

                       

                      2. The script cannot find your tab delimited data file, or it cannot

                      extract the data. Did you add the data file in the correct location? The

                      location from the script in the book would be c:\mydata\Contacts.txt. Also,

                      the name and email address need to be separated by one Tab character.

                       

                      3. The fields need to be named the same way as the columns in the data file

                      (the two names are in the first line of the file).

                       

                      So, check that you are not getting any errors in the JavaScript console

                      (Ctrl-J or Cmd-J), and verify that the tab delimited file is in the correct

                      location

                       

                       

                      Karl Heinz Kremer

                      • 8. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
                        tdjohnson7700 Level 1

                        Karl

                         

                         

                        Thank you for getting back with me!

                         

                        In answer to your questions:

                         

                         

                        1. Your trusted function is not a trusted function. Did you put this

                        function into a folder level script so that it will get executed at system

                        startup?--

                             yes--I saved the script as a .js file and put it in the following path (I have Acrobat XI Pro for Windows)

                         

                        C:\Documents and Settings\tjohnson\Application Data\Adobe\Acrobat\Privileged\11.0\JavaScripts\GetTabData.js

                         

                        2. The script cannot find your tab delimited data file, or it cannot

                        extract the data. Did you add the data file in the correct location? The

                        location from the script in the book would be c:\mydata\Contacts.txt

                        Yes--the file is in the same path as the book.

                         

                        Below is my code that references the file.

                         

                        var cPath = "/c/mydata/Contacts.txt";

                         

                        the slashes in the book go in the direction of the text above--should they go in the direction that you have in your question?

                        Also,  the name and email address need to be separated by one Tab character.

                        They are. 

                         

                         

                        3. The fields need to be named the same way as the columns in the data file (the two names are in the first line of the file).

                        My headings are RevByFromTab and EmailFromTab--which match the names of the two fields on the stamp.

                        So, check that you are not getting any errors in the JavaScript console

                        (Ctrl-J or Cmd-J), and verify that the tab delimited file is in the correct

                        location

                        When I run in the java script console--and I just run the script on the stamp,

                         

                        it says

                         

                        TypeError: event.source is null

                        17:Console:Exec

                        undefined

                         

                        When I place the stamp on the page, the popup box is working, but when you click on the down arrow, there is nothing listed.  When I click OK, the RevByFromTab is populated by the first item in the file, but the EmailFromTab field says undefined.

                         

                        Thank you

                         

                        Message was edited by: tdjohnson7700

                        • 9. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
                          try67 MVP & Adobe Community Professional

                          Regarding the first issue, I always add the following condition to my stamps to prevent it from happening:

                           

                          if (event.source && event.source.forReal && (event.source.stampName == "...")) {

                               // rest of code

                          }

                          • 10. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
                            tdjohnson7700 Level 1

                            Thank you, Gilad, for responding again.

                             

                            I added your script to the stamp script--I already had

                             

                            if(event.source.forReal && (event.source.stampName == "#RevByFromTab"))

                             

                            so i changed it to be

                             

                            if(event.source && event.source.forReal && (event.source.stampName == "#RevByFromTab"))

                             

                            However,--now I have a new problem.  I didn't change anything else about the script.

                             

                            When I place the stamp on a PDF, and do a CtrlJ to look at the java script window, it gives the following error.

                             

                            ReferenceError: Dialog is not defined([object ADMDialog])@App:Calculate:3

                            execDialog([object Object])@:0

                            @App:Calculate:33

                             

                             

                            This is a totally new error--I have never received this before.

                             

                            To Karl or Gilad--

                             

                            could I send you a private message with the text of my stamp script and my java script file?  I just don't feel comfortable posting on the forum since the script does come from a book that you have to purchase.

                             

                            If so--please advise and THANK YOU to both of you for trying to assist me.

                            • 11. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
                              try67 MVP & Adobe Community Professional

                              I highly doubt this change would have caused this problem... Maybe it just allowed the script to progress up to that line, and then fail.

                               

                              Regarding private help: See PM.

                              • 12. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
                                Karl Heinz Kremer Adobe Community Professional

                                I did receive the files directly from tdjohnson7700. Here are my findings:

                                 

                                There are two problems with your files:

                                 

                                You are referencing a "Dialog" object, even though you declared it as "dialog" - JavaScript is case sensitive, so you need to use the lowercase version.

                                 

                                And then you have an extra column of data in your text file, Acrobat does not like this and reports an error. You can see this when you use the Tools>Forms>More Forms Options>Import Data function to import data from your text file. You either have to add a form field named "Last" to your stamp, or you need to remove that column from the text file. After these two changes, the stamp does work.

                                • 13. Re: Acquire data from a tab delimited file using a popup dialog object on a stamp
                                  tdjohnson7700 Level 1

                                  Thank you very much for your assistance, Karl. I really appreciate your help!