I'd like to fetch the latest date between 2 custom fields in case they're exist, as followed:
CF1 exit after status "Active"
While, CF2 may or may not exist.
However, script is not working when the CFs is not exist.
I've written the followed script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import java.text.SimpleDateFormat
import com.atlassian.jira.issue.Issue
import java.util.Date
def LatestDue = new SimpleDateFormat("d/MMM/yy")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf1 = customFieldManager.getCustomFieldObject(FIELD_ID1)
def cf2 = customFieldManager.getCustomFieldObject(FIELD_ID2)
def DueField = issue.getDueDate()
if(cf1 != null && cf2 != null && issue.getCustomFieldValue(cf2).after(issue.getCustomFieldValue(cf1))){
return LatestDue = issue.getCustomFieldValue(cf2)
}else if(cf1 != null && cf2 != null && issue.getCustomFieldValue(cf1).after(issue.getCustomFieldValue(cf2))){
return LatestDue = issue.getCustomFieldValue(cf1)
}else if(cf1 != null){
return LatestDue = issue.getCustomFieldValue(cf1)
}else{
}
Kindly,
Gilad