Missed Team ’24? Catch up on announcements here.

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

Autoclose parent task when linked issues closed

Harish Kumar January 28, 2020

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

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
SITTER_Adrien
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.
January 29, 2020

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

Harish Kumar January 29, 2020

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

SITTER_Adrien
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.
January 29, 2020

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

Harish Kumar January 29, 2020

@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

SITTER_Adrien
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.
January 29, 2020

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

SITTER_Adrien
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.
January 29, 2020

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"

Harish Kumar February 10, 2020

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

1 vote
maro hamamjyan October 16, 2020

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

TAGS
AUG Leaders

Atlassian Community Events