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

Change text color in multiple fields based on expired date.

New Here ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

Hi friends,

 

Im in Acrobat Pro DC and I have multiple fields that I want to turn the text red if the "Expires" cell is any day before today.Expired.

I have a field that already calculates the current date from a Document level script; Today_af_date. Here is that code: 

function dateToday() {
var d = new Date();
f = this.getField("Today_af_date");
f.value = d;
}

dateToday();

 

Here is the code that is in Custom Val Script: of the "Expires" cell - NOTE: I have 52 fields that I need this entered into. Should it be a Document level script? 

 

I'm getting a Syntax error 19 at line 20, as well?

 

var Today = this.getField("Today_af_date").value;
var Expired = event.value;

 

// Check to see if the cells are filled with data
if(Today.length || Expired.length) {

 

// Make sure date values are the same
var dateToday = util.scand("mm/dd/yy", Today);
var dateExpired = util.scad("mm/dd/yy",Expired);

 

// Fire off the validation
if (dateExpired.value<=dateToday.value);{
event.target.textColor = color.red;
this.getField("docLicense.0").textColor = color.red;
this.getField("docLicenseNumber.0").textColor = color.red;
this.getField("docIssueDate.0").textColor = color.red;}

 

// Change them back to black if the Expired Date is changed to Non-Expired
else{
event.target.textColor = color.black;
this.getField("docLicense.0").textColor = color.black;
this.getField("docLicenseNumber.0").textColor = color.black;
this.getField("docIssueDate.0").textColor = color.black;}

}

TOPICS
Acrobat SDK and JavaScript

Views

111

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Sep 02, 2022 Sep 02, 2022

At

 if (dateExpired.value<=dateToday.value);{

remove the ; and .value

Likes

Translate

Translate
Community Expert ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

At

 if (dateExpired.value<=dateToday.value);{

remove the ; and .value

Likes

Translate

Translate

Report

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 ,
Sep 03, 2022 Sep 03, 2022

Copy link to clipboard

Copied

Hi,

Please have a look at the attached file.

In calculate script of the Today_af_date field:

event.value=util.printd("mm/dd/yy",new Date());

and in calculate script of the Expires_af_date field:

if (event.value<=this.getField("Today_af_date").value) {
	this.getField("docLicense.0").textColor=color.red;
	this.getField("docLicenseNumber.0").textColor=color.red;
	this.getField("docIssueDate.0").textColor=color.red;
} else {
	this.getField("docLicense.0").textColor=color.black;
	this.getField("docLicenseNumber.0").textColor=color.black;
	this.getField("docIssueDate.0").textColor=color.black;
}

I didn't understand about your 52 fields!

Dou you have to change the font color of 52 fields if the expires date is before today?

@+

 

Likes

Translate

Translate

Report

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 ,
Sep 07, 2022 Sep 07, 2022

Copy link to clipboard

Copied

LATEST

Thank you for both responces, 

Turns out that I did have a syntax error ( Thank you @Bernd Alheit )

I ended up using my original script with the corrections. 

The simplified script by @bebarth does not activate if the user inputs the date manually. It will run on the first input, but if we want to change the date the script does not run. The colors do not change back to black.

Also, I wanted the target field to change as well. 

 

So, this is what I went with: (this runs no matter the input - manual or selecting the date from the calendar) 

 

var Today = this.getField("Today_af_date").value;
var Expired = event.value;

 

// Check to see if the cells are filled with data
if(Today.length || Expired.length) {

 

// Make sure date values are the same
var dateToday = util.scand("mm/dd/yy", Today);
var dateExpired = util.scand("mm/dd/yy",Expired);

 

// Fire off the calculation
if (dateExpired<=dateToday){
event.target.textColor = color.red;
this.getField("docLicenses.1").textColor = color.red;
this.getField("docLicenseNumber.1").textColor = color.red;
this.getField("docLicenseIssueDate.1").textColor = color.red;}

 

// Change them back to black if the Expired Date is changed to Non-Expired
else{
event.target.textColor = color.black;
this.getField("docLicenses.1").textColor = color.black;
this.getField("docLicenseNumber.1").textColor = color.black;
this.getField("docLicenseIssueDate.1").textColor = color.black;}

}

 

Now I have 52 more sets of these fields to ads this script.

 

Thank you both for the help!

Likes

Translate

Translate

Report

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