Skip to main content
Participant
June 22, 2023
Answered

JavaScript code for automatic date population

  • June 22, 2023
  • 1 reply
  • 522 views

I have an adobe PDF that I am trying to automate for faster processing. I have the pdf I am working with, see attached.

 

I'd like to enter JavaScript code to make it so that when I put the date into the OHARNG entry date box, it auto populates dates that Soldiers would be receiving said award. The number of years after entry date are annotated inside parentheses beside number of award, i.e. "(3)" beside "1st" under the OHAWM column. 

 

Additionally, I would like to conditionally format it so that the date won't physically show up unless it is on or past the current date when the pdf gets opened. 

 

I have searched for hours and cannot seem to find a code or conditional format that will do this.

This topic has been closed for replies.
Correct answer try67

You can use something like this as a doc-level script, so it executes each time the file is opened:

 

var startDateString = this.getField("OHARNG").valueAsString;
if (startDateString=="") {
	this.resetForm(["OHAWM"]);
} else {
	var startDate = util.scand("mm/dd/yyyy", startDateString);
	var prizeDateOHAWM = new Date(startDate.getTime());
	prizeDateOHAWM.setFullYear(prizeDateOHAWM.getFullYear()+3);
	var now = new Date();
	if (prizeDateOHAWM.getTime()>=now.getTime()) {
		this.getField("OHAWM").value = util.printd("mm/dd/yyyy", prizeDateOHAWM);
	} else this.getField("OHAWM").value = "";
	
}

 

Adjust field names and durations as needed.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 22, 2023

You can use something like this as a doc-level script, so it executes each time the file is opened:

 

var startDateString = this.getField("OHARNG").valueAsString;
if (startDateString=="") {
	this.resetForm(["OHAWM"]);
} else {
	var startDate = util.scand("mm/dd/yyyy", startDateString);
	var prizeDateOHAWM = new Date(startDate.getTime());
	prizeDateOHAWM.setFullYear(prizeDateOHAWM.getFullYear()+3);
	var now = new Date();
	if (prizeDateOHAWM.getTime()>=now.getTime()) {
		this.getField("OHAWM").value = util.printd("mm/dd/yyyy", prizeDateOHAWM);
	} else this.getField("OHAWM").value = "";
	
}

 

Adjust field names and durations as needed.