Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

is there a way to close an Epic (or a Story) when all linked issue are closed?

vashim shekh
Contributor
February 13, 2020

is there a way to close an Epic (or a Story) when all linked issue are closed?

 

Please suggest

2 answers

1 vote
Gyorgy Dani-Rauf
Contributor
February 13, 2020
0 votes
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2020

Hi @vashim shekh,

If you have scriptrunner plugin already, then below script will work for you

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.web.bean.PagerFilter

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
IssueService issueService = ComponentAccessor.getIssueService()
def linkManager = ComponentAccessor.getIssueLinkManager()
def searchService = ComponentAccessor.getComponent(SearchService.class)
def actionId = 41 // change this to the step that you want the issues to be transitioned to


def transitionValidationResult
def transitionResult


def epicLink = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Epic Link")
def epic = issue.getCustomFieldValue(epicLink) as String
if(epic){
def issueE = issueManager.getIssueObject(epic);
def jqlSearch = "\"Epic Link\" = ${issueE.key}"
def allDone = true

SearchService.ParseResult parseResult = searchService.parseQuery(currentUser, jqlSearch)
if (parseResult.isValid()) {
def searchResult = searchService.search(currentUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
issues.each { i ->
if (i.getResolution().name == 'Unresolved'){
allDone = false
}
}
}

if(issueE.getStatus().name != "Done" && allDone)
{
transitionValidationResult = issueService.validateTransition(currentUser, issueE.id, actionId,new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.warn("Transitioned issue $issue through action $actionId") }
else
{ log.warn("Transition result is not valid") }
}else{
log.warn("The transitionValidation is not valid")
}

}
}

 

BR,
Leo

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Upcoming Jira Events