I have created two custom date picker fields, START DATE and END DATE. These two fields are used on Create Issue Screen.
I am using script runner addon to I validate END DATE against START DATE.
User should not be allowed to choose an End Date that is much before the Start Date.
As an end result, user should be not allowed to create ticket if END DATE chosen is prior to the START DATE
Request help from the Community !!!
Following is the code that I have added in Script Console:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.web.action.util.CalendarResourceIncluder
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def startDateField = customFieldManager.getCustomFieldObjectByName('Start Date')
def startDateValue = issue.getCustomFieldValue(startDateField)
def endDateField = customFieldManager.getCustomFieldObjectByName('End Date')
def endDateValue = issue.getCustomFieldValue(endDateField)
Calendar calendar = Calendar.getInstance(TimeZone.getDefault())
calendar.setTime(startDateValue)
calendar.setTime(endDateValue)
// validation end date
if (endDateValue != null){
if(startDateValue > endDateValue){
invalidInputException = new InvalidInputException("End Date must be greater than Start Date")
}
// validation start date
if (startDateValue != null){
if(startDateValue > endDateValue){
invalidInputException = new InvalidInputException("End Date must be greater than Start Date")
}
}
// This block validates end date against start date
if (issue.endDateValue) {
if (issue.endDateValue?.before(Calendar.getInstance().getTime()))
{
invalidInputException = new InvalidInputException("End date must be in the future")
}
}
When I run the above code, I get following error: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script177.groovy: 22: expecting ')', found ';' @ line 22, column 23. if(startDateValue > endDateValue){ ^ 1 error