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
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.