Forums

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

How to auto-close Epics if all the stories are closed, with ScriptRunner?

Alexandra Sousa DECSKILL December 11, 2019

Hello Community,

 

I am new at ScriptRunner and I need to close epics when all stories/tasks are closed automatically because we have a lot of epics that are open (despite inside every issue is done) and then, when everything is closed, we still see the Epics in Backlog...

 

So, how to I update the epic status, close it and remove it from the backlogs list without click in every epic "Mark as Done" manually? 

 

Thank you so much in advance!

3 answers

1 vote
Marko Slijepčević
Contributor
December 21, 2020

Has anyone done this for Scriptrunner Cloud?
Thank you!

0 votes
Leo
Community Champion
December 11, 2019

Hi @Alexandra Sousa DECSKILL ,

below code may give you some idea, this is working in server platform

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 

Alexandra Sousa DECSKILL December 12, 2019

Thank you so much for your help! :) 

0 votes
Per Löfgren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2019

Yes, this can be done with Automation for Jira and I am sure it can be done with scriptrunner as well. I have solved the same problem using Automation for Jira. 

Suggest an answer

Log in or Sign up to answer