I have the script which calculates the maximum/larger date from linked issues. However it is not working for Sprint filed. I want to create a scripted field which will display the larger end date from story which is linked within an epic. below is my script:
import com.atlassian.jira.component.ComponentAccessor
import java.text.SimpleDateFormat
//Check that current issue is an Epic
if(issue.issueType.name == "Epic")
{
log.warn("found an Epic")
//Initialize appropriate managers
def linkManager = ComponentAccessor.issueLinkManager
def cfm = ComponentAccessor.customFieldManager
//Get the EpicPlannedCompletion field and initialize a list to hold the date values
def EpicPlannedCompletionField = cfm.getCustomFieldObjectByName("Sprint")
def EpicPlannedCompletionDates = [] as List<Date>
//Loop through all of New Feature's epics and collect their date objects
linkManager.getOutwardLinks(issue.id).each{
if(it.issueLinkType.name == "Issues in epic")
{
def epicIssue = it.destinationObject
if(epicIssue.issueType.name == "Story"){
EpicPlannedCompletionDates.add(epicIssue.getCustomFieldValue(EpicPlannedCompletionField) as Date)
log.warn("added a date")}
}
}
if (EpicPlannedCompletionDates.size()==0){
return null
}
//Initialize min and max
def minDate = EpicPlannedCompletionDates[0] as Date
def maxDate = EpicPlannedCompletionDates[0] as Date
log.warn("piching the first date " + minDate)
//Find actual min and max Dates
for(int i = 1; i < EpicPlannedCompletionDates.size(); i++)
{
log.warn("Iteration "+i)
def currentDate = EpicPlannedCompletionDates[i]
if (currentDate!=null && minDate != null) {
if(currentDate.before(minDate))
{
minDate = currentDate
}
if(currentDate.after(maxDate) && maxDate!= null)
{
maxDate = currentDate
}
}
else { //Moving "currentDate" into "minDate" and "maxDate" as soon as currentdate is no null
minDate = currentDate
maxDate = currentDate
}
}
//If I was unable to find any dates associated with the epic
if(minDate == null || maxDate ==null){
return null
}
return maxDate
}
else //Return null if issue is not an Epic
{
return null
}