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

Adobe Pro Javascript Datepicker - If within 30 days from today

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

TOPICS
Acrobat SDK and JavaScript

Views

361

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 , Aug 28, 2020 Aug 28, 2020

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 op

...

Votes

Translate

Translate
Community Expert ,
Aug 27, 2020 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.

Votes

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 Beginner ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

I wondered about that, thank you for the insight.

Votes

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 ,
Aug 28, 2020 Aug 28, 2020

Copy link to clipboard

Copied

What should it be if it's neither?

Votes

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 ,
Aug 28, 2020 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();

Votes

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 Beginner ,
Aug 28, 2020 Aug 28, 2020

Copy link to clipboard

Copied

LATEST

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

Votes

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 Beginner ,
Aug 28, 2020 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!

Votes

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