Copy link to clipboard
Copied
Hi again, everyone! I came here a while back looking for help on a script to import a tab delimited txt file, creating forms with the imported data, and then saving them to specific folders based on a certain field's data. Below is the pastebin for that code and it's commented out to show what each bit is for.
[JavaScript] PDF Form Saving - Pastebin.com
I'm wanting to dumb this down a bit so that, instead of importing data to create the forms, a user will: fill out the form, choose the menu item according to what type of form it is, and the script then uses the PFFSID field data to use in the Switch portion to determine the folder it is to be saved in at the end of the script.
I thought that if I simply removed the While loop that the Switch section would be able to pass all necessary data to the SaveAs command, but I was wrong and I'm not exactly sure why. If you'd like to lend a hand please let me know any questions you might have so I can be as useful as possible.
Thanks!
NEW UPDATE: I put these three line above the switch statement:
whichCert = this.getField("PFFSID").valueAsString;
whichCase = String(whichCert).indexOf("z");
firstThree = String(whichCert).substr(0,3);
and it's working! YEAHOOOOOOOOO! I guess I had to specify to pull it as a string since I'm pulling straight from the document rather than a text file like I was with the original script.
Got a new weird thing though, not a problem really, just a quirk with Acrobat.
If I type, "1z" in and use the scrip
...Copy link to clipboard
Copied
Seems like it should work, if the field is populated... What exactly happens when you use it?
Copy link to clipboard
Copied
Sorry Try67, stuff got hectic at work and stepped away from this for a bit, I'll clarify what I'm asking. The above script works as intended but it's not what I want to do with it anymore. Currently, it is importing data from a text file and batch creating several pdf forms from that data, but we've now moved past the point in the project to need to batch create.
I need to alter this script so that it only focuses on the form the user has open and filled out. It should flow like:
> define the variable whichCert by pulling the value in field PFFSID of currently open and filled in form
> using that value to our variable whichCase so it can index where, or if, there is a "z" in the value
> using whichCase in our Switch statement to determine what folder it needs to be saved to according to the index value
> passing several values to the SaveAs function at the end of the function (this part should work once the other pieces are, I assume)
Here is the script I thought could accomplish this by removing the text import and while loop from the original code: [JavaScript] Attempt - Pastebin.com
Sadly, I don't even see it appear in the submenu I create with a different script in the folder so I can't even run it to test, so I'm assuming that means the script is just broken and Adobe doesn't want to touch it.
That said, I just don't know what I'm doing wrong. I'm guessing that just defining both whichCert, and its dependent variable whichCase outside the Switch statement and then just hoping Switch would pick it up is what I'm doing wrong. I just don't know how to fix it.
I know my other script that works kicks off Switch within a While loop, so do I have to use some other method to pass the variable to it first? Or is it something to do with defining both variables outside the loop at the same time? Sorry for the novel, but I'll be on the forums everyday searching for an answer so I'll be more timely with any replies.
Thanks again
Copy link to clipboard
Copied
Let's start from the beginning: I'm not seeing any command in your code to add a menu or toolbar item to call this function, so why do you think it will be there?
Acrobat doesn't just "give up". If there's an error in the code, it will report it. If you don't see any error then it means you didn't do something to cause an error but you also didn't build the code correctly to achieve what you had in mind.
Copy link to clipboard
Copied
Oh, it's located at the very bottom. The submenu it's getting added to is added in by another script in my adobe folder. I have several other scripts setup with the same code, but with different script names of course, and they all are added to the submenu just fine.
Copy link to clipboard
Copied
Was it there before? I guess I missed it. Sorry.
Anyway, I copied the code to a .js file in Acrobat's Javascripts folder and the sub-menu and menu items appear just fine.
Are there no error messages when you open the application in the JS Console?
Copy link to clipboard
Copied
NEW UPDATE: I put these three line above the switch statement:
whichCert = this.getField("PFFSID").valueAsString;
whichCase = String(whichCert).indexOf("z");
firstThree = String(whichCert).substr(0,3);
and it's working! YEAHOOOOOOOOO! I guess I had to specify to pull it as a string since I'm pulling straight from the document rather than a text file like I was with the original script.
Got a new weird thing though, not a problem really, just a quirk with Acrobat.
If I type, "1z" in and use the script, the file gets created.
Then I type in "10z" and hit enter and then use the script the proper file is created.
But if I then change the "10z" to a "1z" and use the script without hitting enter or activating another field, the script then saves over the 10z file, preserving the name of it, but with "1z" in the field.
I don't think this should be an issue because they will be entering data into other fields after this one, but any ideas on how to make that not happen?
Copy link to clipboard
Copied
The value is not committed until you exit the field.
Copy link to clipboard
Copied
Thanks for all the help again, try67!
Copy link to clipboard
Copied
Put the line
firstThree = String(whichCert).substr(0,3);
before the switch
The menu will only added when the sub-menu "Import Scripts" exists.