Hi All, I need help on creating a script that verifies if the end date cannot be selected before start date
I have these 2 Date time picker custom field named Start Date and End Date. I need to put validation using scriptrunner . can someone help? Thank you
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("Impact Start")
def startDateValue = issue.getCustomFieldValue(startDateField)
def dueDateField = customFieldManager.getCustomFieldObjectByName("Impact End")
def dueDateValue = issue.getCustomFieldValue(dueDateField)
Calendar calendar = Calendar.getInstance(TimeZone.getDefault())
log.warn "starDateValue ${startDateValue}"
calendar.setTime(startDateValue)
int startDateDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)
log.warn "starDateValueweek ${startDateDayOfWeek}"
calendar.setTime(dueDateValue)
int dueDateDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)
// validation due date
if (dueDateValue != null ){
if(startDateValue > dueDateValue){
invalidInputException = new InvalidInputException("Due Date must be greater than Start Date")
}
}
// validation start date
if (startDateValue != null){
if(startDateValue > dueDateValue){
invalidInputException = new InvalidInputException("Due Date must be greater than Start Date")
}
}
// validation duedate
if (dueDateValue) {
if (issue.dueDate?.before(Calendar.getInstance().getTime())) {
invalidInputException = new InvalidInputException("Due date must be in the future.")
}
}
it throws these errors

