Hi,
I have two optional fields 'GT Dev Start Date' and ' GT Dev End Date'. I would want it to be optional as in user can choose to skip filling the dates if not needed.
But in scenarios where an user chooses to fill the dates(both Start and End) I would like to validate that the End Date is not smaller than the Start Date.
Could you please help me with a script for the same. I have developed something myself(am still new to scripting) but it makes it mandatory to fill the dates, thereby dissolving the purpose.
Sharing the script-
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
import com.atlassian.jira.component.ComponentAccessor
import groovy.transform.BaseScript
import com.atlassian.jira.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.core.util.StringUtils
@BaseScript FieldBehaviours fieldBehaviours
def optionsManager = ComponentAccessor.getOptionsManager()
// Get the Custom Field Manager
CustomFieldManager FieldManager = ComponentAccessor.getCustomFieldManager()
def startDateField = getFieldByName("GT Dev Start Date")
def startDateValue = startDateField.getValue() as Date
def endDateField = getFieldByName("GT Dev End Date")
def endDateValue = endDateField.getValue() as Date
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(endDateValue)
int dueDateDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)
// validation end date
if(endDateValue == null){
return;}
if(endDateValue != null ){
if(startDateValue > endDateValue){
def invalidInputException = new InvalidInputException("End Date must be greater than Start Date")
}
}
// validation start date
if (startDateValue == null){
return;}
if (startDateValue != null){
if(startDateValue > endDateValue){
def invalidInputException = new InvalidInputException("End Date must be greater than Start Date")
}
}