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...
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
...Copy link to clipboard
Copied
You don't need a button for update/refresh. You can change the color at document open.
Copy link to clipboard
Copied
I wondered about that, thank you for the insight.
Copy link to clipboard
Copied
What should it be if it's neither?
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();
Copy link to clipboard
Copied
It worked like a charm! Thank you for your time and selflessness to help me out!
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!