Skip to main content
Participating Frequently
June 27, 2024
Answered

EASY SOLUTION FOR SOMEONE, JUST NOT ME

  • June 27, 2024
  • 2 replies
  • 1815 views

I HAVE 2 FIELDS. A "TEST DATE" FIELD, WHICH I HAVE SETUP TO AUTOMATICALLY FILL IN TODAY'S DATE. FORMATED WITH DATE.

 

I HAVE ANOTHER FIELD "REG DATE" WHICH IS FORMATED THE SAME AS DATE. HOWEVER, THIS FIELD IS MANUALLY SELECTED BY THE USER.

 

WHAT I'D LIKE TO DO IS MAKE THIS "REG DATE" FIELD DISPLAY GREEN AND RED BASED ON THE DATE ENTERED. GREEN IF IT IS NOT PAST THE "TEST DATE" FIELD, BUT RED IF IT IS PAST "TEST DATE" FIELD. 

 

ANY IDEA'S HOW TO ACCOMPLISH THIS?

This topic has been closed for replies.
Correct answer try67

THANK YOU SO MUCH THIS DOES WORK. I BELEIVE IT PROBABLY WORKED THE LAST TIME TOO BUT I HAD MY FORM SET TO HIGHLIGHT ALL REQUIRED FIELDS AND THAT'S WHY IT WASN'T SHOWING UP AFTER YOU SELECTED THE DATES.

 

THE ONLY ISSUE I SEEN ON IT WAS THE ISSUE OF IF BOTH FIELDS HAVE THE SAME DATE IN THEM, THEN REG DATE IS RED. THAT SHOULD BE GREEN OR TRANSPARENT SO TO SPEAK. I'D LIKE TO GO AHEAD AND REMOVE THE GREEN AND JUST USE TRANSPARENT FOR GOOD TO GO AND RED FOR EXPIRED REGISTRATIONS. I TRIED TO TOY WITH THAT A LITTLE AND GOT A FEW ERRORS ON SYNTAX AND SUCH. 


Change the code to this:

 

if (event.value) {
	var testDate = util.scand("mm/dd/yyyy", this.getField("TESTDATE").valueAsString);
	testDate.setHours(0);
	testDate.setMinutes(0);
	testDate.setSeconds(0);
	testDate.setMilliseconds(0);
	var regDate = util.scand("m/d/yy", event.value);
	regDate.setHours(0);
	regDate.setMinutes(0);
	regDate.setSeconds(0);
	regDate.setMilliseconds(0);
	event.target.fillColor = (regDate.getTime()<testDate.getTime()) ? color.red : color.transparent;
} else event.target.fillColor = color.transparent;

2 replies

try67
Community Expert
June 28, 2024

- What is the date pattern used in these fields?

- What should be the color if the two dates are the same?

- What should happen if "TEST DATE" is empty and "REG DATE" is not?

Participating Frequently
June 28, 2024

THE DATE PATTERNS ARE:

- What is the date pattern used in these fields? "TEST DATE:"  FIELD IS: MM/DD/YYYY | "REG EXPIRE DATE:" FIELD IS: MM/DD/YY

- What should be the color if the two dates are the same? "TEST DATE:" FIELD SHOULDN'T CHANGE ANY COLORS

I WANT TO GET THE "REG EXPIRE DATE:" FIELD TO CHECK AGAINST THE TEST DATE FIELD. IF IT IS AN EARILER DATE THAN THE CURRENT DATE, I WANT IT TO FLAG THE FIELD RED. I DON'T NEED IT TO DO ANY GREEN AFTER I WAS THINKING ABOUT IT BUT, IF I DID, I'D LIKE IT TO BE GREEN IF IT'S GOOD, RED IF IT'S EXPIRED BASICALLY.

- What should happen if "TEST DATE" is empty and "REG DATE" is not? NEITHER OF THESE FIELDS CAN BE EMPTY. THEY ARE REQUIRED TO BE FILLED IN OR THE DOCUMENT WON'T ALLOW PRINTING. I HAVE THAT FIELD SCRIPTED TO AUTO ENTER THE CURRENT DATE WHEN THE PDF IS OPENED. 

 

 

try67
Community Expert
July 11, 2024

IS THERE ANY HELP OUT THERE THAT SOMEONE CAN GIVE ON THIS SIMPLE SOLUTION THAT I'M NOT ABLE TO GET TO WORK?


I didn't get a notification about your reply from earlier due to a bug in the forums system...

You can use this code as the custom calculation script of the "REG DATE" field:

 

if (event.value) {
	var testDate = util.scand("mm/dd/yyyy", this.getField("TEST DATE").valueAsString);
	var regDate = util.scand("mm/dd/yyyy", event.value);
	event.target.fillColor = (regDate.getTime()<testDate.getTime()) ? color.red : color.green;
} else event.target.fillColor = color.transparent;
Amal.
Community Manager
Community Manager
June 27, 2024

Hi there

Hope you are doing well and thanks for reaching out.

The workflow you are trying to achieve is might be possible using JavaScript. For more information, please check the help pages listed below:
https://acrobatusers.com/tutorials/javascript_console/
https://helpx.adobe.com/acrobat/using/applying-actions-scripts-pdfs.html

Hope it will help

Regards
Amal