Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I prevent users from selecting a date in the past?

Ashley Honeycutt
Contributor
May 23, 2025

I've tried both Scriptrunner validators and behaviors, but I'm not quite getting there.

I need to prevent users from submitting tickets where they select a date in the past. I'm using the Due Date field, but can replace it with a custom field instead if needed.

 

Thank you!

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Lucas Modzelewski _Lumo_
Atlassian Partner
May 23, 2025

I asked Chat GPT and here is proposed solution:

Here’s a sample Groovy script you can use in a Script Validator on a transition (e.g. Create or Update):

import java.time.LocalDate

// Replace with your custom field ID or name
def dateField = getFieldByName("Start Date")

if (!dateField || !dateField.getValue()) {
return true // allow if field is empty
}

def selectedDate = dateField.getValue() as LocalDate
def today = LocalDate.now()

return !selectedDate.isBefore(today)

If Date is in the Past, this will block the transition and display a generic error. You can customize the error message by adding:

return selectedDate.isBefore(today) ? "The selected date cannot be in the past." : true

--
I hope that helps!

DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events