These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Using mailMsg script with form data

DTjava
Registered: Jun 17 2011
Posts: 21
Answered

Hi everyone,
 
I'm trying to populate an email body with form data. I've found the relevant entries in the acrobat API, but I still can't seem to integrate their examples together into my form.
 
As a test I put this in a button mouseup action:
 
var cMyMsg = "Below are the current budget figures:\n\n";
cMyMsg += "Date Compiled: " + this.getField("date").value + "\n";
cMyMsg += "Current Estimate: " + this.getField("budget").value + "\n";
app.mailMsg({
bUI: true, cTo: "myBoss [at] example [dot] com", cSubject: "The latest budget figures", cMsg: cMyMsg } );
 
All that came direct from the API. But nothing happens when I click the button. I then tried to swap the order, putting the var cMyMsg second after the app.mailmsg entry. This fires up the email, but doesn't include the custom message body fields. I'm thinking I don't have this nested properly, but I don't know much about javascript.
 
Any ideas? End result I'm looking for is a button that loads up an email to a preset address and a body populated from the form data.
 
Thanks!

My Product Information:
Acrobat Pro 9.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
First of all, the definition of cMyMsg must come before the command that sends the mail.
Are there any error messages in the console when you run this code?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

DTjava
Registered: Jun 17 2011
Posts: 21
Yup - Console smacked me in the head and told me to define the values of the fields! Sorry, still getting used to having the console open to point me in the right direction. Basically the email wouldn't load up until the values were pointing to my own (properly named) text fields.

And thanks for the tip on cMyMsg coming first...took out one of the variables for me.

Fist bump.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You probably misspelled the name of one or more of the fields. Remember it's case sensitive, so if your field is called "Budget" then trying to access "budget" will fail.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Another small tip: Under Edit - Preferences - JavaScript, tick the option to show the console on errors and warnings. That way you don't need to keep it open all the time. It will pop up in case of problems with your code.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

DTjava
Registered: Jun 17 2011
Posts: 21
Nice tip! Thanks!