Skip to main content
lindag76738329
Participant
December 9, 2019
Question

PDF Form - Autofill a "late fee" based on date

  • December 9, 2019
  • 1 reply
  • 502 views

Is it possible to have a field automatically filled with a $50 late fee if the date field is after April 10, 2020?

How do I do that?

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
December 9, 2019

Yes. You can use this code as a doc-level script, via Tools - JavaScript - Document JavaScripts:

var cutoffDate = util.scand("mm/dd/yyyy", "04/10/2020");
var now = new Date();
this.getField("Fee").value = (now.getTime()>cutoffDate.getTime()) ? "50" : "";

 

Do not put it inside the function body that is created automatically when adding a new script, though. Replace that with the code above.

lindag76738329
Participant
December 9, 2019

Thank you so much! However, it didn't work. I had to vary from your instructions a couple of times. Perhaps the problem is with one of these?

- I am using Acrobat 9.0. I found Document Java Scripts not in the Tools tab, but in the Advanced tab under Document Processing. Once there, I replaced what automatically came up with your code.

- I also edited your code to read "Late Fee" in place of "Fee" because that is what the field is named.

Any idea where I've gone wrong?

https://www.dropbox.com/s/zhgzbor93z2g14e/Screenshot%202019-12-09%2016.08.35.png?dl=0 

try67
Community Expert
Community Expert
December 9, 2019

After applying the code you must save the file, close it and then re-open it. Of course, unless you change your system date nothing will appear in the field... However, you should open the JS Console (Ctrl+J) after opening the file to see if there are any error messages in it. If you still can't figure it out share the actual file with us, please.