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

JS on Archive button for acrobat form

Tracy@EForm
Registered: Feb 3 2009
Posts: 8
Answered

I am trying to save a form by inserting JavaScript into a button in an acrobat form. The field names I have put into the formare AccountName and AccountNumber; the form should be saving itself as; AccountNumber-AccountName-Date.pdf. Here is the JS I have so far; and it only seems to work sometimes. Can anyone help me figure out what is wrong with my archive button??? It either saves the form as AccountName-date.pdf or AccountNumber-date.pdf; I can't get it to read all three fields.

//Mouse up action of Save button, only works if there is an associated .js file in Adobe's Javascript folder on the user's hard drive

//This statement gets the value that is entered into a field
var a = this.getField("AccountNumber");

//This statement assigns that value as a variable to be used later
var av = a.value;

var b = this.getField("AccountName");
var bv = b.value;

//This statement pulls today's date to be used for naming the file
var cv = util.printd ("ddmmmyy", new Date());

var z = this.getField("dash");
var zx = z.value;

//This statement calls the function in the .js file and uses the stored variables to name the .pdf
myTrustedSpecialTaskFunc(this, "/c/Save_Folder/" + av + zx + bv + zx + cv + ".pdf");

//This statement controls the what is written on the title bar of the pop-up
var dialogTitle = "** FORM SAVED TO C: DRIVE **";

//This statement creates the pop-up and the verbiage that is written in the pop-up
var reply = app.alert({ nIcon:3, cMsg: "\nThis form has been saved to Save_Folder on the C: drive.\n\nPress OK, then close the browser window.", cTitle: dialogTitle, nIcon: 3, nType: 0});

this.closeDoc(true);

My Product Information:
Acrobat Pro Extended 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Instead of using the value field property in your code, try using the valueAsString property. For example:

var av = a.valueAsString;
And you probably don't need to store the dash character in a field. You could do this instead:

var zx = "-";
or

"/c/Save_Folder/" + av + "-" + bv + "-" + cv + ".pdf"
George
Tracy@EForm
Registered: Feb 3 2009
Posts: 8
Thanks, the dash part works perfectly but it still will only save the form by grabbing one field only! Thanks, I'm going to try and play with it some more.
Tracy@EForm
Registered: Feb 3 2009
Posts: 8
I found the problem, as silly as it was... I was entering in info into the fields, but not clicking out of the field before I hit my archive button, so there was no info entered into the field technically for the form to be saved as.

Also, George helped me simplify this JavaScript very well and I wanted to say what George gave me was dead on. Thank you very much for your help!