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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How Close an Epic when all issues in Epic are closed using Scriptrunner

Hi Guys,

I need some help to close my Epic when all issues in Epic are closed, I followed this documentation https://library.adaptavist.com/entity/close-an-epic-when-all-the-issues-under-that-epic-are-closed,

The Scriptrunner shows the aren't errors in my code, but this post function in Stories can't work properly.

Also I did three changes.

final String actionName = "Closed" I changed to final String actionName = "Done"

final String issueLinkName = "Epic-Story Link" I changed to final String issueLinkName = "Epic Link"

*.destinationObject?.findAll { it.status.statusCategory.name != "Complete" } I changed to *.destinationObject?.findAll { it.status.statusCategory.name != "Done" }

Someone used this documentation and worked right?

Also I tried with Done, DONE, done, Epic Name, Epic Link and Issues in Epic

 

Can someone help me?

Thanks, 

Fabio

 

2 answers

1 accepted

Here the final code, this worked for me.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.TransitionOptions

// the name of the action you want to move the issue to
final String actionName = "Done"

// 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 (!epicIssue) {
return
}
def workflow = ComponentAccessor.workflowManager.getWorkflow(epicIssue)
def actionId = workflow.allActions.findByName(actionName)?.id

// 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 { it.status.statusCategory.name != "Complete" }

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

def issueService = ComponentAccessor.issueService
def issueInputParameters = issueService.newIssueInputParameters()

issueInputParameters.setComment("This Epic closed automatically because all the issues in this Epic are closed.")
issueInputParameters.setSkipScreenCheck(true)

def transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def transitionValidationResult = issueService.validateTransition(loggedInUser, epicIssue.id, actionId, issueInputParameters, transitionOptions)
assert transitionValidationResult.isValid() : transitionValidationResult.errorCollection

def result = issueService.transition(loggedInUser, transitionValidationResult)
assert result.isValid() : result.errorCollection

Can you explain the reasons for your changes ? I have the impression that you changed things without really knowing what you are changing and what the impact is ?

I changed to final String actionName = "Done" : your epic workflow action to "close" the Epic is called like this ?

I changed to final String issueLinkName = "Epic Link" : I think "Epic Link" is the name of a custom field of issues in epics, but is not link name ? Why do you change this ???

I changed to *.destinationObject?.findAll { it.status.statusCategory.name != "Done" } : I think "Done" is not a valid Jira status category ! Why do you change this ?

Hi  @Marc Minten _EVS_ 

Done its my last transition and work flow status.

About "Epic Link" you are right, it's the name of field link, but the link name in Jira is "Issues in Epic" also I tried this name and doesn't work. I did changes trying to catch the rigth name of link and the name showed in script can't work.

Done it's the last statuscategory in Jira.

If I just copy this code https://library.adaptavist.com/entity/close-an-epic-when-all-the-issues-under-that-epic-are-closed, can't work properly here, then I did the changes according with my work flow.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you