12 Replies Latest reply on Sep 15, 2015 11:52 AM by amyr28466165

    Javascript and button help...

    amyr28466165

      I have a portfolio of forms I have created to use along with other counselors in my school district to simplify filling out what has become a huge program and part of our job...a very time consuming one I might add too.  I created this to save time with what has become what we do as school counselors (paperwork) with the goal to allow more time to do what we as counselors actually went to school to do, want to do, and love to do...spend time counseling and helping our students.  Last year I converted our district forms to fillable pdf files and then had some help developing the portfolio and the scripts that help it operate the way we needed it to.  I have learned a lot about pdf, pdf forms, and javascript but now I am running into trouble on a part we want to add. 

       

      Within the portfolio I have several forms.  Several of the forms have the same form fields.  So I have one pdf document (the main information form) that has a javascript to copy data entered into all forms that have the same form fields.  This prevents us from having to enter in the same info over and over (student name, ID, etc. etc,).

      Then within certain forms I have a very similar script for users to click a button and copy data from that one form over to the Spanish form (this is great because we fill out the English form and can copy all that data entered over to the Spanish form with the click of a button for Spanish speaking/reading parents).


      EXAMPLE OF WHAT I HAVE (btw which works beautifully!!!)...


      A pdf doc titled "Meeting Forms."  This form has the following document level javascript.

          // the list of files to process:

        var lPortfolioFiles = [ "(I) Meeting Forms (Spanish).pdf" ];

       

        function CopyDataToFile(source, dest) {

          // iterate over all form fields in the destination form and copy from

          // the field with the same name from the source (if available)

          for (var i=0; i<dest.numFields; i++) {

              var fieldName = dest.getNthFieldName(i);

              var f1 = source.getField(fieldName);

              if (f1 != null) {

                  dest.getField(fieldName).value = f1.value;

      console.println("Field name: " + fieldName + "\nData = " + f1.value);

              }

            }

      }

       

      function CopyData(doc)

      {

        // what is our file name?

        var myFileName = doc.path;

        // get the portfolio part of the path

        var re = /(\|.*\|)(U:(\uFEFF|\uFFFE)<0>)(.*)/;

        var res = myFileName.match(re);

        console.println(res[3]);

        // process all files in the list

        for (var i in lPortfolioFiles) {

        var fileName = res[1] + res[2] + lPortfolioFiles[i];

        var d2 = app.openDoc(fileName);

        CopyDataToFile(doc, d2);

        }

      }

       

      On the form I have a "Copy to Spanish" button with the following javascript

        CopyData(this);

      and the Spanish Form has the following document level javascript

        this.disclosed = true;

       

      WANT I NEED NOW AND CANNOT FIGURE OUT...

      I want to add another button/script to this same form that operates almost the same way.  I want the additional button to open another form within the portfolio.  So, I want it to operate exactly the same but just open the form for use not copy data into it.  I thought this would be simply modifying and using the above script but after countless hours and frustration I seem to only be stuck in the same place...nowhere.  Just when I thought I had learned so much Javascript. Ughhh.

      I want to avoid using the "linking" method because after trying that users complained about continuously accidentally exiting out of the portfolio instead of the individual document (the linking method seems to open the linked forms differently).

      Any help/example scripts to make this happen would be GREATLY APPRECIATED

        • 1. Re: Javascript and button help...
          Karl Heinz Kremer Adobe Community Professional

          Are you getting any error messages on the JavaScript console?

           

          I have not worked with JavaScript in portfolios in a while, but based on what I see, it should work. You may want to display the original filename and the modified name on the console. The problem is that the unicode \ufeff will not show up correctly when you just print the string, so you have to use the toSource() operator to get the whole string. Try something like this:

           

          function CopyData(doc) {
            // what is our file name?
            var myFileName = doc.path;
            console.println(myFileName.toSource()); // DEBUG OUTPUT
            // get the portfolio part of the path
            var re = /(\|.*\|)(U:(\uFEFF|\uFFFE)<0>)(.*)/;
            var res = myFileName.match(re);
            console.println(res[3]);
            // process all files in the list
            for (var i in lPortfolioFiles) {
            var fileName = res[1] + res[2] + lPortfolioFiles[i];
            console.println(fileName.toSource()); // DEBUG OUTPUT
            var d2 = app.openDoc(fileName);
            CopyDataToFile(doc, d2);
            }
          }
          
          

          Does anything obvious show up in the debug output?

          • 2. Re: Javascript and button help...
            amyr28466165 Level 1

            Sorry for the delay.  Unless I am doing something wrong which is very possible then the above did not work.  I am not very familiar with how the Javascript console.  If you have an email and wouldn't mind I would love to email you the portfolio.  I figure it might make more sense if you were able to see how the buttons function differently.  One of the buttons works beautifully.  If I could get them all to work the same that would be ideal...if it is possible.

            • 3. Re: Javascript and button help...
              Karl Heinz Kremer Adobe Community Professional

              Could you create a very basic version of your portfolio and upload it to e.g. Adobe's Document Cloud (http://cloud.acrobat.com) or Dropbox and then share the link here? If that's not possible, send me a PM (via the "Message" button on my profile page).

              • 4. Re: Javascript and button help...
                amyr28466165 Level 1

                Let me know if this works or not.  This is the first time I have uploaded anything on the acrobat cloud.

                https://cloud.acrobat.com/file/1d60f8db-593b-4bef-86be-51ec542a1258

                • 5. Re: Javascript and button help...
                  amyr28466165 Level 1

                  If it does an example of what I am talking about is on the "Meeting Forms - Forms 7, 8, and 16."  The button "C Spanish Forms" is how I would like the other buttons (i.e. "Open Service Plan", etc.) to work.

                   

                  Also on a side note...In Acrobat DC my tab button does not allow me to tab through the form fields.  Any idea why that might be?

                  • 6. Re: Javascript and button help...
                    Karl Heinz Kremer Adobe Community Professional

                    I am getting a file not found error - you need to share the file via the "Send" feature, which will then give you a URL that you can post.

                    • 7. Re: Javascript and button help...
                      amyr28466165 Level 1

                      That makes sense.  Let me try this again...

                      Shared Files - Acrobat.com

                      • 8. Re: Javascript and button help...
                        Karl Heinz Kremer Adobe Community Professional

                        The reason this is not working is because you do not have the Spanish documents in the list of documents to process. I just added one of the missing documents:

                         

                           // the list of files to process:
                           var lPortfolioFiles = [ "(B) Teacher - Form 4 Annual Input.pdf", "(C) Meeting Notice and Parent Input (English).pdf",
                            "(D) Meeting Forms - Form 7 Form 8 and Form 16 (English).pdf", "(E) Service Plan - Forms 9 and 11 (English).pdf",
                            "(E2) Form 11 - Additional Notes Pages2.pdf", "(F) BIP - Form 10 (English).pdf", "(G) Manifestation - Form 12 (English).pdf",
                            "STAAR-A Documentation Forms (English).pdf", "(I) Meeting Forms (Spanish).pdf" ];
                        

                         

                        This now correctly updates the Spanish version of the "Meeting Forms" document.

                         

                        BTW: The tab key should work, just as it did in Acrobat XI or earlier.

                        • 9. Re: Javascript and button help...
                          amyr28466165 Level 1

                          The Spanish button works perfectly.  I do not have it in the initial document "Student Information Sheet" because we do not always need the Spanish version.  So instead I placed it on the individual English documents (C Spanish Form).  No need to process all those Spanish documents unless they are needed. 

                           

                          For example:  Let's say I fill out a Student Profile Sheet on a student.  I hit the 'copy' button which pushes all that information into each document I have listed, basically the English docs, with the same form fields (by the way that magical process alone is simply amazing and a huge help for us educators).  During the meeting I work/type only on the English docs (wish I could read and speak Spanish but unfortunately I can't).  However, if the student's parents are Spanish speakers I can simply click the 'C Spanish Forms' button, it copies all the form field info into the Spanish version.  All I have to do is click print.  All this is working just as I would like it to.

                           

                          Recently I had request  to add a few additional buttons (i.e. "Open Service Plan, Open BIP, Add More Notes, etc...")  I want to program these buttons to open the same way as the Spanish Forms open when that button is clicked.  I do not need any form fields to be copied.  Notice how they open is different.  The coordinators working in the portfolios end up exiting out of the portfolio by accident after they have clicked "Open Service Plan" because that is how they are used to closing the Spanish forms once they have clicked the button to open them.  I could not figure out how to get the other buttons to open like the Spanish Forms button so I used the 'create a link' option...which as I said before is not working so well with users. 

                           

                          I am not sure if that helps make any more sense of what I am asking and/or trying to do....

                          • 10. Re: Javascript and button help...
                            amyr28466165 Level 1

                            That is what I find very very strange...the tab key is not working when I open the portfolio in DC.  However, if I use my laptop or another computer with XI or earlier it works just as it used to.

                            • 11. Re: Javascript and button help...
                              Karl Heinz Kremer Adobe Community Professional

                              Ah, now I understand. Sorry for the confusion.

                               

                              First, all documents open the same way. It's just that you don't see the behavior when you click on the main "Copy" button because you are closing the documents right away again. If you remove the call to close the document, you will see that they all are opened as separate windows, not inside the Portfolio window.

                               

                              When you go to the "Meetings Form" document, and click on the two buttons, you will see a difference in behavior: One of them opens the document in the same window as your original Portfolio, and puts a header on top that allows you to switch back to the portfolio view, the other (Spanish) does not. When you close the Spanish document, your portfolio is still open. I would recommend to always open inside the same window and then teach your users how to use the form ("If you see this in the upper left corner, then click on the little "x" to get back to the Portfolio").

                               

                              To do that, you will have to adjust your button action: In the JavaScript action, close the document that you copied the data to again, and then add a second action of "go to a document view". This should give you a consistent behavior.

                              • 12. Re: Javascript and button help...
                                amyr28466165 Level 1

                                So, there is no way to give the other buttons a document level script like the Spanish button to open the way the Spanish button opens the Spanish forms?