I'm trying to write a custom script on validator for following requirement
When User selects ABC component it makes due date mandatory (for other component it'll be there but not mandatory), and if user enters the duedate before 3 date from today then it'll throw an error(again only for ABC component) . I have written following script but it's not working. Any suggestions? Thanks in advance!
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import com.opensymphony.workflow.InvalidInputException
import java.util.Date.*
def formComponent = getFieldByName("Component")
def dueDate = getFieldById("customfield_12204")
def createdDate = getFieldById("customfield_14364")
def cfval = cf.getValue() as Date
// get todays date
def today = new Date()
// get the date three months in the future
def threeDaysDate = today.plus(3)
//def today = new java.sql.Timestamp(new Date().getTime())
def componentFieldValues = formComponent.value
if (componentFieldValues*.name?.contains("ABC")){
dueDate.setHidden(false)
dueDate.setRequired(true)
if(cfval.before(threeDaysDate)) {
cf.setError("##ERROR##")
// if the date entered is over three months throw an error
} else{
cf.clearError()
}
}
//else {
//dueDate.setHidden(true)
//}