Hi,
I want to do a validation which needs to pick date between current day and custom field date (BOM due date).
Please find the script below:
if(issue.dueDate.compareTo(cfValues["BOM Due Date"]) <= 0)
{
return true
}
else
false
The issue I am facing is that it is taking past dates. For future dates, the script is working fine.
For example:
BOM due date: 21/06/2019
Due date: 21/06/2019
Issue is created
BOM due date: 28/6/19
Due date: 30/06/2019
Error message is displayed
BOM due date: 28/6/19
Due date: 4/06/2019
No error message is displayed. The validation should work as it should not allow to pick past date.
Please advice.
Thanks,
Swarna
Can you specify your question better? You're talking about "current date" but it is not mentioned in your condition.
So if you're validationg due date, condition should be for both cases:
if(issue.dueDate.compareTo(cfValues["BOM Due Date"]) >= 0 && issue.dueDate.compareTo(new Date()) <= 0){
return true;
}
if(issue.dueDate.compareTo(new Date()) >= 0 && issue.dueDate.compareTo(cfValues["BOM Due Date"]) <= 0){
return true;
}
Hi Martin,
Thanks for the script above.
When I test for same date, error message is displayed. Please see screenshot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the problem is that you're using Date field which does not save time part of the date (which is correct) but new Date() creates date with current time. So instead of new Date() try to create Date instance with one of the methods mentioned here:
https://www.baeldung.com/java-date-without-time
For example:
public
static
Date getDateWithoutTimeUsingCalendar() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,
0
);
calendar.set(Calendar.MINUTE,
0
);
calendar.set(Calendar.SECOND,
0
);
calendar.set(Calendar.MILLISECOND,0
);
return
calendar.getTime();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.