I have two date and time fields start date and end date, when user trying to edit date fields if end date is less than start date should throw an error, if start date is empty then it should clear the error and allow user to enter any date in end date, also if end date is greater than start date error should clear.
I wrote below script it's working when start date is not empty, but when I empty the entire field (start date) manually, error is not cleared, but when I clear partially that is if I just remove time or anything from field partially then it's cleared the error. I'm not sure why error is not cleared when I completely emptied the start date, please suggest where I'm doing wrong, below is the script which I wrote.
I also tried for empty field
// startDateStr =="" || startDateStr ==null || startDateStr.toString().trim().isEmpty but nothing worked, please suggest
import java.lang.Exception
import org.apache.xmlgraphics.util.DateFormatUtil
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FormField
import com.onresolve.jira.groovy.user.FieldBehaviours
import java.text.SimpleDateFormat
def endDate = getFieldByName("End Date")
def startDate = getFieldById(fieldChanged)
def startDateValueStr = startDate.getValue() as String
def startDateValue = startDate.getValue() as Date
def endDateValue = endDate.getValue() as Date
if (!startDateValueStr) {
endDate.clearError()
}
if (startDateValue && endDateValue.before(startDateValue)) {
endDate.setError("The End Date cannot be before the Start Date.")
} else {
endDate.clearError()
}