Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need to have document save via Javascript with text field

New Here ,
Apr 23, 2019 Apr 23, 2019

I am have created an interactive pdf file that runs a script that generates a new form # when text field is selected. The problem is that when the end-user fills out their document with the new number, they will also perform a SaveAs with the new number that was generated from the script, and they existing blank pdf document that they started with will still have the existing file number because it was not saved. So, I need to have a way to have this document automatically save when the end-user clicks the text field that generates the new number, so it will save the new generated number when the next user opens the blank form. The reason is because the next user will need to have the correct to take out in succession instead of 0001 because the file was never saved or updated.

I have found a few different scripts online. People seem to say that app.execMenuItem("Save"); is what works, however, it does not seem to work within my text field script.

This is what my text field script looks like.

var f = this.getField("Result1");

f.value = util.printf("%05d", Number(this.getField("Result1").value)+1);

f.defaultValue = f.value,(100);

var f = this.getField("TodaysDate");

f.value = util.printd("mm/dd/yyyy", new Date());

app.execMenuItem("Save");

Thank you so much!! Any help is appreciated!!

TOPICS
PDF forms
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2019 Apr 23, 2019

First of all, this line is incorrect and will result in an error:

f.defaultValue = f.value,(100);

Just use:

f.defaultValue = f.value;

If you want to save the file automatically you have to install a script on the local machine of each user.

If you can't do that then you can only open the Save dialog, and the user will need to save it manually.

This is what the execMenuItem command does, but the name of the item is "SaveAs", not "Save".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 23, 2019 Apr 23, 2019

Thank you so much,ty67, for the feedback. This does answer part of my question. I am fine with having then end-user Save the file themselves, but the problem is that I still need one of two things to happen. If I am setting the script to perform a SaveAs, and they give the file a new file name, I still need the existing file to save as well, and that is the current issue. The reason that I need both files to save is because the end-user is going to click the Text Field that will generate a new #, and that number needs to be updated on the template as well as their file that they created with the SaveAs script function. The reason is because the template file will always have the 0001 number instead of being updated to the most recent number that needs to generated for the latest Release #,  So, that template file needs to update as well to keep up with the latest release # for the end user. So, the next person will generate the latest number required instead of the 0001 that the template has. You had said with your post that “If you want to save the file automatically you have to install a script on the local machine of each user.” If you could help me out with the script to perform the automatic save, that would be greatly appreciated.

Thank you again!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2019 Apr 23, 2019
LATEST

You can't rely on these numbers to be unique, unless there's only one copy of the file in use. As soon as more than one person uses it, you'll start getting duplicate numbers. You should switch to either time-based numbers, or random ones, or assign the ID numbers on your end, once the form has been submitted back to you.

Regarding saving the file automatically, read this tutorial: https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines