10 Replies Latest reply on Dec 3, 2008 3:06 PM by (JR_R)

    Generate email text from form data

      I am trying to stumble my way through some relatively simple JavaScripting in Acrobat & InDesign to improve our workflow in a very overworked environment.

      One of my goals is to generate an email that merges text from a PDF form into the email message itself. Ideally, as the form is being completed the user could simply push a button that opens an email with the desired form information (only a few fields) then simply hit send.

      Any help is very much appreciated.

      Thanks!
      -Scott
        • 1. Re: Generate email text from form data
          Patrick Leckey Level 3
          Check the documentation for the Doc.submitForm() method. Set the cURL to a mailto link like "mailto:email@company.com".

          This will attach form data to the e-mail as well, but the cBody parameter can be set to any text.

          If you want an e-mail with no attachment and just text, you'll have to use the app.launchURL() method and define the message body as one of the parameters in a standard mailto URL schema, such as:

          var myBody = "This is the message body".
          var myURL = "mailto:email@company.com?subject=Email&body=" + myBody;
          app.launchURL(myURL, true);
          • 2. Re: Generate email text from form data
            Level 1
            I think that I am following, but how would I use data from the form as part of the text in the email? Essentially, my email would be sending a request to another department to prepare a document that I need to provide that is based upon specific information collected in the form. (Client Name, Address, etc...)

            I will dig into the Doc.submitForm() method as you advise. I would simply attach the form data, but that would introduce a change and sometimes that isn't accepted so readily :-)

            Thanks.
            -Scott
            • 3. Re: Generate email text from form data
              Patrick Leckey Level 3
              Well you can use JavaScript to extract the field values and then include them in your body variable - I only gave a simplistic example.

              For example (since I don't know any of your field names or if the form were created in Acrobat or Designer):

              var cClientName = this.getField("ClientName").value;
              var cAddress = this.getField("Address").value;

              var cBody = "Client Information:\n\n";
              cBody += "Client Name: " + cClientName + "\n";
              cBody += "Address: " + cAddress + "\n";

              var myURL = "mailto:email@company.com?subject=Client Info&body=";
              myURL += cBody;

              app.launchURL(myURL, true);

              That will open an e-mail window with a body containing the data from AcroForm fields named "ClientName" and "Address".
              • 4. Re: Generate email text from form data
                Level 1
                I apologize for being so ignorant ... I am trying to get this.

                So, if I create a button in Acrobat and select on MouseUp ... Run Javascript ... then type (or paste) the code with my variable names from the Acrobat Form ... it should open an email window in my Outlook.

                I must be missing something because it doesn't appear to do anything when I click on the button.

                Thank you for your patience and help ... if I can grasp the basics of this, it will apply many, many times to make life much easier for myself and many colleagues.
                • 5. Re: Generate email text from form data
                  Patrick Leckey Level 3
                  Hit CTRL+J after clicking on the button. That will bring up the JavaScript Console and show you any errors you're getting. If you want, paste them in here (anything after the line reading "Acrobat SOAP 8.0").
                  • 6. Re: Generate email text from form data
                    I have been trying to achieve a similar solution. Clicking on a button will use data from the form as part of the text in the email. I have followed the instructions on this post but have got the following errors after clicking Ctrl+J in my preview form.

                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    syntax error
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseEnter
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    syntax error
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseEnter
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    syntax error
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseEnter
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    syntax error
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:click
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp
                    this.getField is not a function
                    1:XFA:form1[0]:#subform[0]:Header[0]:Button1[0]:mouseUp

                    Please help. Thanks.
                    • 7. Re: Generate email text from form data
                      Bernd Alheit Adobe Community Professional & MVP
                      The instructions on this post are not for a Designer-created form.
                      • 8. Re: Generate email text from form data
                        Patrick Leckey Level 3
                        > this.getField

                        This method doesn't exist in XFA forms, only in AcroForms. You need to re-write your JavaScript for XFA forms if you are developing your solution in LiveCycle Designer. One major thing to realize is that in LiveCycle Designer, "this." never refers to the Doc object as it usually does in AcroForms, so you'll need to acquire your Doc object via "event.target".

                        You'll also need to replace any getField calls with the XFA equivalent, "xfa.resolveNode".

                        You should probably start by reading this document, which explains the difference between AcroForm JavaScript and XFA JavaScript methods:
                        http://www.adobe.com/devnet/livecycle/articles/AcroJS_DesignerJS.pdf
                        • 9. Re: Generate email text from form data
                          Level 1
                          Thanks for your replies.

                          I have followed the document linked and have replaced the code. However now when click the preview the email opens I get [object XFAObject] where the field values should appear.This is the code I'm using.

                          var cPurpose = event.target.xfa.resolveNode("form1[0].Sub[0].Purpose[0]").value;
                          var cProject = event.target.xfa.resolveNode("Project").value;

                          var cBody = "Thanks for your request for the following work:\n\n";
                          cBody += "Purpose: " + cPurpose + "\n";
                          cBody += "Project: " + cProject + "\n";

                          var myURL = "mailto:email@company.com?subject=Client Info&body=";
                          myURL += cBody;

                          app.launchURL(myURL, true);

                          Sorry I'm a new to Livecycle and don't understand script.
                          • 10. Re: Generate email text from form data
                            var cClientName = this.getField("ClientName").value;
                            var cAddress = this.getField("Address").value;

                            var cBody = "Client Information:\n\n";
                            cBody += "Client Name: " + cClientName + "\n";
                            cBody += "Address: " + cAddress + "\n";

                            var myURL = "mailto:email@company.com?subject=Client Info&body=";
                            myURL += cBody;

                            app.launchURL(myURL, true);

                            How do you keep the PDF attachement with the email? Presently, there are no email attachment.