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!
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.
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")
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