Skip to main content
Participating Frequently
June 4, 2021
Question

Calculating expiry date based on document open date

  • June 4, 2021
  • 3 replies
  • 968 views

Hi,

I am trying to set an expiry date for the pdf form from the day the document open for the first time. I wrote the following javascript to the page properties - 

var ExpDate = new Date();

ExpDate.setDate(ExpDate.getDate()+60);

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

if (f.value == "") {

f.value=util.printd("20yy/mm/dd", ExpDate);

event.target.readonly = true;

}

var dateField = this.getField("Today");

if (dateField.value == "") {

dateField.value = util.printd("yyyy/mm/dd", new Date());
event.target.readonly = true;

}

The code picked up today's date and calculate the expiry date. 

Problem: the problem is every day I open the document, it picks todays date and recalculate the expiry date. How can I fix the day the document is open for the first time so that the expiry date does not change every day? Any help is appreciated!

 

This topic has been closed for replies.

3 replies

try67
Community Expert
Community Expert
June 4, 2021

This is quite useless. Unless the file is saved the initial date will never be set and the user can use it for as long as they wish, and even if it did expire they can just go back to the original file and start over.

 

Also, I know it's not a big deal, but please don't do stuff like this:

util.printd("20yy/mm/dd", ExpDate);

Why introduce the Y2K-bug into your code on purpose? Just use "yyyy".

Participating Frequently
June 4, 2021

Agree with you. But this is what I am assigned to and I need to show that the document will be expired and inaccessible after 60 days. The user can always go back to the original file and start over. Thanks!

Nesa Nurani
Community Expert
Community Expert
June 4, 2021

Do you save file after you open it with calculated dates?

I assume you use code at document level so event.target.readonly won't do anything change it to f.readonly and dateField.readonly.

Participating Frequently
June 4, 2021

I will modify the code as you suggested and lets see how that works. Will update.

Bernd Alheit
Community Expert
Community Expert
June 4, 2021

Have you saved the document?

Participating Frequently
June 4, 2021

I saved the document but still get the same results.

Bernd Alheit
Community Expert
Community Expert
June 4, 2021

It will only change the value of the fields when the the fields are empty.

Does you use a reset form?