Highlighted

Adobe Pro Javascript Datepicker - If within 30 days from today

Community Beginner ,
Aug 27, 2020

Copy link to clipboard

Copied

Hello all, I'm not a javascript coder by any stretch, but I do understand coding... I'd like, if someone is willing, to help be with a script that changes a datepicker (dp1) strokeColor based on whether or not it's within 60 days (yellow) or 30 days (red) from today - all using the format yyyymmdd (in the Army lol)

 

For example, today is 20200827 and if the date selected is 20201005 then the border of the date picker would turn yellow...

 

Lastly, a button that would update/refresh the datepicker to ensure it was still accurate strokeColor..

 

Apologies for not having a working solution, I'm a noob...

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Assuming that black, you can use this code as the field's custom calculation script:

 

var customStrokeColor = color.black;
var s = event.value;
if (s) {
	var d = util.scand("yyyymmdd", s);
	var now = new Date();
	var diff = d.getTime()-now.getTime();
	var diffInDays = Math.floor(diff/86400000);
	if (diffInDays<30) customStrokeColor = color.red;
	else if (diffInDays<60) customStrokeColor = color.yellow;
}
event.target.strokeColor = customStrokeColor;

 

In order to update it when the file is opened add the following command under Tools - JavaScript - Document JavaScripts (NOT inside a function!):

 

this.calculateNow();

Topics

Acrobat SDK and JavaScript

Views

69

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

Adobe Pro Javascript Datepicker - If within 30 days from today

Community Beginner ,
Aug 27, 2020

Copy link to clipboard

Copied

Hello all, I'm not a javascript coder by any stretch, but I do understand coding... I'd like, if someone is willing, to help be with a script that changes a datepicker (dp1) strokeColor based on whether or not it's within 60 days (yellow) or 30 days (red) from today - all using the format yyyymmdd (in the Army lol)

 

For example, today is 20200827 and if the date selected is 20201005 then the border of the date picker would turn yellow...

 

Lastly, a button that would update/refresh the datepicker to ensure it was still accurate strokeColor..

 

Apologies for not having a working solution, I'm a noob...

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Assuming that black, you can use this code as the field's custom calculation script:

 

var customStrokeColor = color.black;
var s = event.value;
if (s) {
	var d = util.scand("yyyymmdd", s);
	var now = new Date();
	var diff = d.getTime()-now.getTime();
	var diffInDays = Math.floor(diff/86400000);
	if (diffInDays<30) customStrokeColor = color.red;
	else if (diffInDays<60) customStrokeColor = color.yellow;
}
event.target.strokeColor = customStrokeColor;

 

In order to update it when the file is opened add the following command under Tools - JavaScript - Document JavaScripts (NOT inside a function!):

 

this.calculateNow();

Topics

Acrobat SDK and JavaScript

Views

70

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
Aug 27, 2020 0
Adobe Community Professional ,
Aug 27, 2020

Copy link to clipboard

Copied

You don't need a button for update/refresh. You can change the color at document open.

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
Reply
Loading...
Aug 27, 2020 1
Community Beginner ,
Aug 27, 2020

Copy link to clipboard

Copied

I wondered about that, thank you for the insight.

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
Reply
Loading...
Aug 27, 2020 0
Most Valuable Participant ,
Aug 28, 2020

Copy link to clipboard

Copied

What should it be if it's neither?

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
Reply
Loading...
Aug 28, 2020 0
Most Valuable Participant ,
Aug 28, 2020

Copy link to clipboard

Copied

Assuming that black, you can use this code as the field's custom calculation script:

 

var customStrokeColor = color.black;
var s = event.value;
if (s) {
	var d = util.scand("yyyymmdd", s);
	var now = new Date();
	var diff = d.getTime()-now.getTime();
	var diffInDays = Math.floor(diff/86400000);
	if (diffInDays<30) customStrokeColor = color.red;
	else if (diffInDays<60) customStrokeColor = color.yellow;
}
event.target.strokeColor = customStrokeColor;

 

In order to update it when the file is opened add the following command under Tools - JavaScript - Document JavaScripts (NOT inside a function!):

 

this.calculateNow();

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
Reply
Loading...
Aug 28, 2020 1
Community Beginner ,
Aug 28, 2020

Copy link to clipboard

Copied

It worked like a charm! Thank you for your time and selflessness to help me out!

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
Reply
Loading...
Aug 28, 2020 0
Community Beginner ,
Aug 28, 2020

Copy link to clipboard

Copied

Thank you try67!! I will give it a shot in a couple hours, but I've seen your work on a lot of problems through this forum and I'm certain it's correct. I appreciate your time/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
Reply
Loading...
Aug 28, 2020 0