Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,359,878
Community Members
 
Community Events
168
Community Groups

Autoclose parent task when linked issues closed

Hi All,

 

Can you help me out in auto-transition of parent issue to closed when all its linked issues are closed within the same project. (Adaptavist Scriptrunner)

waiting for an early reply.

thanks

Harish Kumar

2 answers

1 accepted

0 votes
Answer accepted

Hello @Harish Kumar,

Scriptrunner provides a build-in post-function to do this.

Create a post-function on the transition to close in every subtask workflow. Select "Script Post-Function [ScriptRunner]" then "Transition parent when all subtasks are resolved".

This will look at the resolution of every subtasks of the parent, if all subtasks have a resolution it will make the transition.

Regards,

Adrien

@SITTER_Adrien  , My query is related to linked issues, not for subtasks...

Sorry I read parent and in my mind I stucked with subtask.

You can use this script: https://library.adaptavist.com/entity/close-an-epic-when-all-the-issues-under-that-epic-are-closed

You should change:

  • actionName: name of the transition in parent issue workflow
  • issueLinkName: name of the link type between the parent and the linked issue (otherwise even duplicate, blocks, etc will need to be closed)
  • You can remove or edit the comments (line starting with issueInputParameters.setComment)

You should put this script as a custom post-function of closing transition on every worfklow of issue that can be linked by the issueLinkName link type.

Regards,

Adrien

@SITTER_Adrien Hi, I have edited the code, and the final code looks like this:

 

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 = "Closed"

// the name of the issue link
final String issueLinkName = "Cloners"

def workflow = ComponentAccessor.workflowManager.getWorkflow(issue)
def actionId = workflow.allActions.findByName(actionName)?.id
def issueLinkManager = ComponentAccessor.issueLinkManager

def epicIssue = issueLinkManager.getInwardLinks(issue.id).find { it.issueLinkType.name == issueLinkName }?.sourceObject
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 { it.status.statusCategory.name != "Closed" }

// 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 Issue closed automatically because all the linked-issues in this Issue 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

 

 

Query : I need to put this code in the workflow transition of all linked issues and parent issues where the final status is there ? can you explain me please.

 

Thanks

HArish

So from what I see you have a parent issue which is linked to other issue with "is cloned by" relation (which names is "Cloners"). This is one of the default issue linking relation of Jira.

The issues that are linked to your parent issue have one or several workflows (if you have different issues type with different workflow).

For each of this workflow you have to edit every transition making your issue going to a "Closed" states (that can be one or several, depending of your workflow). For each of this transition, add a post-function of type "Script Post-Function [ScriptRunner]" > "Custom script post-function" and paste the code you have adapted.

Regards,

Adrien

I just saw that you change 

it.status.statusCategory.name != "Complete"

To

it.status.statusCategory.name != "Closed" 

 

This will not work. This line does not look for the status name but the status category name which can only be "New",  "In Progress" or "Complete"

Hi @SITTER_Adrien  , thanks for the support. it works as expected. 

Hi @SITTER_Adrien , will you please help me too?

I try to make the same process work in Service Desk type project. The status categories there are "To Do", "In Progress",  "Done". I changed the code you provided for my case, but it didn't work, will you please have a look and tell me the reason?

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 = "Resolved"

// the name of the issue link
final String issueLinkName = "Problem/Incident"

def workflow = ComponentAccessor.workflowManager.getWorkflow(issue)
def actionId = workflow.allActions.findByName(actionName)?.id
def issueLinkManager = ComponentAccessor.issueLinkManager

def epicIssue = issueLinkManager.getInwardLinks(issue.id).find { it.issueLinkType.name == issueLinkName }?.sourceObject
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 { it.status.statusCategory.name != "Done" }

// 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 Issue closed automatically because all the linked-issues in this Issue 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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

175 views 1 6
Read article

Atlassian Community Events