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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,458,290
Community Members
 
Community Events
176
Community Groups

How to auto close parent issue when all linked issues are closed using script runner

How to auto close an parent issue when all its subtasks are closed in the same project. 

I am trying this by using script runner for JIRA.

Can you guys help me out from here .

Thanks

Harish Kumar

1 answer

2 votes
Leo Community Leader Dec 20, 2019

Hi @Harish Kumar,

There is built-in post-function available in scriptrunner called "Transition parent when all subtasks are resolved"

and below script also can do the same for you

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.bc.issue.IssueService

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
IssueService issueService = ComponentAccessor.getIssueService()
def linkManager = ComponentAccessor.getIssueLinkManager()
def searchService = ComponentAccessor.getComponent(SearchService.class)
def actionId = 41 //41 is my final state transition ID


def transitionValidationResult
def transitionResult

if(issue.getIssueType().name == "Sub-task"){
def allDone = true
ApplicationUser user = issue.getAssignee()
def parent = issue.getParentObject()
parent.getSubTaskObjects()?.each { subtask ->
if(subtask.getStatus().name == "Unresolved" && subtask != issue)
{
allDone = false
}
}
if(allDone){
transitionValidationResult = issueService.validateTransition(currentUser, parent.id, actionId,new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.warn("Transitioned issue $issue through action $actionId") }
else
{ log.warn("Transition result is not valid") }
}else{
log.warn("The transitionValidation is not valid")
}

}
}


 BR,

Leo

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events