Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Sprint End date needed to be updated from last story in the sprint.

siva
Contributor
September 1, 2019

I need to automatically update the Sprint end date .

 

The End date of the SPRINT should be the last STORY complete date in the sprint.

1. Any default option in jira ?

2. Any available option with script runner.

 

NEW CASE :

1,Epic end date should dynamically get updated based on story tagged to last created Sprint 

 

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry
Community Champion
September 5, 2019

Hi @siva ,

See this script : 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.status.category.StatusCategory
import java.sql.Timestamp;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue

// the name of the issue link
final String issueLinkName = "Epic-Story Link"
def issueLinkManager = ComponentAccessor.issueLinkManager

def epicIssue = issueLinkManager.getInwardLinks(issue.id).find { it.issueLinkType.name == issueLinkName }?.sourceObject

//If the story is not attached to an Epic, do nothing
if (!epicIssue) {
return
}

// Find all the linked - with the "Epic-Story Link" link - issues that their status is not completed
def linkedIssues = issueLinkManager
.getOutwardLinks(epicIssue.id)
.findAll { it.issueLinkType.name == issueLinkName }
*.destinationObject?.findAll { StatusCategory.COMPLETE != it.status.statusCategory.key}

// If there are still open linked issues (except the one in transition) - then do nothing
if (linkedIssues.size > 0){
return
}

int dateFieldId = 11200
def dateField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(dateFieldId)
def dateFieldValue = epicIssue.getCustomFieldValue(dateField)

int sprintFieldId = 10100
def sprintField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(sprintFieldId)
def sprintFieldValue = issue.getCustomFieldValue(sprintField)?.endDate?.first()?.toDate()

if (sprintFieldValue){
dateField.updateValue(null, epicIssue, new ModifiedValue(dateFieldValue, new Timestamp(sprintFieldValue.getTime())), new DefaultIssueChangeHolder())
} else {
dateField.updateValue(null, epicIssue, new ModifiedValue(dateFieldValue, new Timestamp(new Date().getTime())), new DefaultIssueChangeHolder())
}

attach it to the last transition of the story workflow. It will update the end date value of the epic if all linked stories are in a green status. The end date value will either be : 

  • The end date of the sprint linked to the story
  • The transition date of the story if it has no sprint (or if there is no end date)

(Check your field ids beforehand)

Hope that is what you are asking for.

Antoine

Antoine Berry
Community Champion
September 6, 2019

Hi @siva ,

Did that work as intended ?

siva
Contributor
September 6, 2019

@Antoine Berry 

 

Tried a work aroud..!!

Mission Accomplished. :)

 

Thank u..!!

Antoine Berry
Community Champion
September 6, 2019

@siva You are very welcome ! 

Please mark this answer as accepted so it can help others in the future.

Suggest an answer

Log in or Sign up to answer