Skip to main content
Example scripts
arrow icon
To homepage
Jira
Data centre icon
Data Center

A post-function for deleting all subtasks of the current issue

Created 1 year ago, Updated 5 month(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira (8.0 - 8.19)
compatibility bullet
ScriptRunner For Jira (7.10.0)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.util.BuildUtilsInfo
import org.ofbiz.core.entity.DelegatorInterface

final int JIRA_8_9_0 = 809000

def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def delegatorInterface = ComponentAccessor.getComponent(DelegatorInterface)
def buildUtilsInfo = ComponentAccessor.getComponent(BuildUtilsInfo)

def subTasks = issue.getSubTaskObjects()

subTasks.each { subTask ->
    // add a condition here if you want to delete selective subtasks
    issueManager.deleteIssue(user, subTask, EventDispatchOption.ISSUE_DELETED, false)
    if (buildUtilsInfo.applicationBuildNumber >= JIRA_8_9_0) {
        delegatorInterface.removeByAnd("IssueVersion", [issueId: subTask.id, deleted: 'Y'])
    }
}
Having an issue with this script?
Report it here