Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically delete sub-tasks

Callum Carlile _Automation Consultants_
Community Champion
January 28, 2019

I have a workflow that creates 5 different subtasks via different transitions. I have a global 'Cancel' transition to close the task on the parent workflow and all sub-task worflows.

I have this built-in code from Adaptavist:

import com.atlassian.jira.component.ComponentAccessor

def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def subTasks = issue.getSubTaskObjects()
subTasks.each {
if (it.statusObject.name == "Closed") {
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
setResolutionId(10301) // resolution of "Fixed"
setComment("*Resolving* as a result of the *Resolve* action being applied to the parent.")
setSkipScreenCheck(true)
}

// validate and transition subtask
def validationResult = issueService.validateTransition(null, 10317, 41, issueInputParameters)
if (validationResult.isValid()) {
def issueResult = issueService.transition(user, validationResult)
if (!issueResult.isValid()) {
log.warn("Failed to transition subtask ${it.key}, errors: ${issueResult.errorCollection}")
}
} else {
log.warn("Could not transition subtask ${it.key}, errors: ${validationResult.errorCollection}")
}
}
}

When I test it, nothing is working, and the logs in the post function say that there are no problems. I have searched the internet and the community questions high and low for an answer but have had no luck.

Please may someone help me with what values I need to enter and where, and if this will close all my subtasks or if i need to copy certain bits of code and reuse them for different subtasks

 

1 answer

0 votes
Callum Carlile _Automation Consultants_
Community Champion
January 28, 2019

There is this code which is meant to work:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
// for JIRA v6.*
def user = ComponentAccessor.getJiraAuthenticationContext().user.directoryUser
// for JIRA v7.*
// def user = ComponentAccessor.getJiraAuthenticationContext().user
def issueManager = ComponentAccessor.getIssueManager()
// will return a Collection<Issue> with all the subtasks of the current issue
def subTasksList = issue.getSubTaskObjects()
for (subTask in subTasksList) {
// add a condition here if you DO NOT want to delete all the sub-tasks
issueManager.deleteIssue(user, subTask, EventDispatchOption.ISSUE_DELETED, false)

But the last line issueManager.deleteIssue(user, subTask, EventDispatchOption.ISSUE_DELETED, false) is not working (I have tried to find an updated version of this for Jria 7.1 and above but can't find it anywhere).

Suggest an answer

Log in or Sign up to answer