Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Prevent users from entering a date in the past

We have created a custom date field and we want to prevent users from selecting a date in the prior month or even a date in the past.

Is there a standard way of achieving this or is there a plug-in that is available.

Any help would be appreciated...thanks!

2 answers

1 accepted

If you are using this field only on workflow transitions, you can use some of the existing validators.

But if you want this field on the edit screens, you would need a new custom field type that does this validation. That will be a new plugin I guess.

Do you have the name of the existing validator that may work, all I see for Validators is Date Compare and Window dates that relate to the dates. Is it one of those?

I don't remember which one it was. Can you try Date Compare and validate your Date field is after updated date?

Thanks Jobin, we got the Date Compare to work for us.

If you want to use the Groovy Runner Script plugin to validate you could use this code which validates that the entered date/time is from this month or later. I'm not sure if existing plugins can check this exactly

import org.apache.log4j.Category
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.opensymphony.workflow.InvalidInputException
 
// replace 10000 by number of date time custom field that must be validated 
def fieldname = "customfield_10000"

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField field = customFieldManager.getCustomFieldObject(fieldname)
 
Date value = issue.getCustomFieldValue(field)
Calendar now = Calendar.getInstance()
Calendar entered_date = Calendar.getInstance()
entered_date.setTime value

if (entered_date.get(Calendar.MONTH) == now.get(Calendar.MONTH) && entered_date.get(Calendar.YEAR) == now.get(Calendar.YEAR))
	return;
	
if (now.before(entered_date))
	return;
	
invalidInputException = new InvalidInputException("Entered date is invalid! Must be from this month or later")

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you