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

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

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

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across Jira Cloud instance.   📢 Get y...

131 views 6 6
Read article

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