13 Replies Latest reply on Aug 13, 2014 5:39 PM by Jo_2013

    Send email from an array of active documents

    Jo_2013 Level 1

      I have a button on a form called "Mail Merge" which brings to the front  another active and saved opened form named "Request for Tender".

       

      Once the "Request for Tender" form is brought to the front the script is to generate an email with the form attached  then close the form, leaving the original form open for regeneration.

       

      The script will actually bring the "Request for Tender" form to the front, but the email that is generated after this, has the first and original form attached and not the form that the focus has been set to.

       

      Can anyone please advise how to fix this so that the correct form is attached to the email?  Any advice greatly appreciated - thank you

       

      Button Script

      var p = this.getField("PackageName");
      var v = this.getField("VendorName");

      var d = app.activeDocs;
      for (var i = 0; i < d.length; i++)
      if (d[i].documentFileName == "Request for Tender " + p.value + v.value + ".pdf") d[i].bringToFront();

       

       

       

      // Email to client

      this.mailDoc({
      bUI: false,
      cTo: "",
      cCC: "",
      cSubject: "Request for Tender " ,
      cMsg: "Please find attached request for tender." + "\n" + "\n" + "Please fill in and return"
      });
      this.closeDoc(true);

        • 1. Re: Send email from an array of active documents
          try67 MVP & Adobe Community Professional

          Are these files disclosed? If not, this won't work.

          Also, you should change all references to "this" in the last part of the

          code to "d[i]"...

          • 2. Re: Send email from an array of active documents
            Jo_2013 Level 1

            Thank you very much for your reply.

             

            I have done the following to modify the script:

             

            • Changed the script in the last section from "this" to "d[i]"
            • In mailDoc changed the "bUI to true"

            • Page open event added the script "this.disclosed = true;"

            • Added {} brackets after the activeDocs if statement.

             

            This modified script works when tested in the console.

             

            However it does not work from the button in the original form.

             

            The script will bring the "Request for Tender" form to the front, but it does not generate an email or close the file.

             

            Can you please advise why it will work from the console but not from the button?

             

            Many thanks, look forward to your reply.  Have included the modified script as follows:

             

            var p = this.getField("PackageName");
            var v = this.getField("VendorName");

            var d = app.activeDocs;
            for (var i = 0; i < d.length; i++)
            if (d[i].documentFileName == "Request for Tender " + p.value + v.value + ".pdf") {
            d[i].bringToFront();

            d[i].mailDoc({
            bUI: true,
            cTo: "",
            cCC: "",
            cSubject: "Request for Tender " + p.value + " " + v.value,
            cMsg: "Please find attached request for tender." + "\n" + "\n" + "Please fill in and return"
            });
            d[i].closeDoc(true);
            }

             


            • 3. Re: Send email from an array of active documents
              try67 MVP & Adobe Community Professional

              So what exactly happens? Are there any error messages in the JS console?

              Also, maybe you should move the script that discloses the file from the

              Page Open event to a doc-level script.

              • 4. Re: Send email from an array of active documents
                Test Screen Name Most Valuable Participant

                You are setting disclosed for the OTHER documents, not this one?

                • 5. Re: Send email from an array of active documents
                  Jo_2013 Level 1

                  There are no error messages in the console when the disclosed statement is in the page open event.

                   

                  The script stops when the "Request for Tender form" is brought to the front, the email is not generated.

                   

                  I tried moving the disclosed statement from page open event  to a document level script, but when this was called from the button there was a console error "not allowed due to security restrictions".

                   

                  Is there something I have not done right? I have not had much experience with document level scripting.

                   

                  Document Level Script

                  function Disclose() {

                  this.disclosed = true;

                  }

                   

                  Called from the button

                  Disclose();

                   

                  Appreciate the help you are giving me thank you.

                  • 6. Re: Send email from an array of active documents
                    Jo_2013 Level 1

                    The first document has the disclose statement in the page open event, this form is then extracted and saved to a predefined directory and then reopened with folder level javascript.

                     

                    The extracted and saved second document has the disclosed statement set to the page open event as well.

                     

                    Thank you for your reply.

                    • 7. Re: Send email from an array of active documents
                      Test Screen Name Most Valuable Participant

                      Still not clear, sorry. You must set disclosed in each of the documents in your array, separately, and before starting. Have you done this?

                      • 8. Re: Send email from an array of active documents
                        Test Screen Name Most Valuable Participant

                        That is, you cannot do it in this script nor in any other.

                        • 9. Re: Send email from an array of active documents
                          Jo_2013 Level 1

                          I will explain the process as follows:

                           

                          • Original form has a folder level javascript to import text data into form fields which is assigned to a button.
                          • After the "import data" button is clicked, the first row of data values are shown in the text form fields.
                          • There is a "mail merge" button which extracts the original form and saves to a predefined directory and is then re-

                            opened as a newly merged form (button calls this from a folder level script).
                          • This new form is then brought to the front as the active document with the scripting from the buttons, and is to then have an email generated and the form will close.  (the email generation is what is not working and there is no console error showing)
                          • The original form will then have the "import data" button clicked for the second row of data values, and from there another new form will be generated etc.
                          • The original form has the "disclosed statement" in the page open event.
                          • When the second form is extracted it is saved to a predefined directory and then reopened before the "app.activeDocs;" script starts.  This second form has the "disclosed" statement in the page open event as well.

                           

                          Should the disclose statement work in this case as it is in the page open event of the second newly generated form?

                           

                          Thanks for your assistance, appreciated your help and guidance.

                          • 10. Re: Send email from an array of active documents
                            Test Screen Name Most Valuable Participant

                            Well, I've never heard of disclosed being used in a page level script. Might work, might not. Everyone else puts it in a document level script, so it may be worth focussing on what goes wrong when you try that. What did you have exactly?

                            • 11. Re: Send email from an array of active documents
                              Test Screen Name Most Valuable Participant

                              Actually you can readily check if the disclosed failed. Check if the elements of activeDocs are NULL and put out a message if they are NULL.

                              • 12. Re: Send email from an array of active documents
                                Test Screen Name Most Valuable Participant

                                Ah, I see you posted what you were doing. No, you don't define a routine. That cannot work. You delete the lines which make it a routine and have a document level script with only the single line needed.

                                • 13. Re: Send email from an array of active documents
                                  Jo_2013 Level 1

                                  Yes, this now works, "thank you so much".

                                  The document level script is called "Disclose"

                                  and the script is "this.disclosed = true;"

                                   

                                  The original form will have row data imported, new form extracted saved and reopened, second form will become the active document, email generated and then file closed.

                                   

                                  The orginal form will then have the second row of data imported etc, great work thanks again.

                                   

                                  One more problem I have to iron out.

                                   

                                  With the folder level script to import text data, this works and steps through each row of data.

                                  After the last record is reached, when the button is clicked, it loops back to the first row and starts again.

                                   

                                  Can you please advise what I need to do so that after the last row of data is reached the loop will end, and it will not go back to the first row of data.  The folder level script is as follows:

                                   

                                  var mailmerging = app.trustedFunction(function(doc)

                                  {

                                  app.beginPriv();

                                  // Import the first row of data from "Mailmerge.txt"

                                  var myPath = "/h/Drawing Office/PDF/Scripting Form Fields/Mail Merge/Mailmerge.txt"

                                  doc.importTextData(myPath, 0)


                                  if (typeof cnt == "undefined") cnt = 0;
                                  doc.importTextData(myPath, cnt++ % 4)

                                   


                                  app.endPriv();


                                  });

                                   

                                  Really appreciate your help, if this can be fixed the form will finally be finished (I have been working for weeks on this), thank you.