Post Function - Deleting all Sub-Tasks of specific type

Rok Antolic December 11, 2015

Hello,

since it is not possible to set separate delete permissions for Sub-Tasks, I have to look into other solutions so I came upon this idea https://devblog.xing.com/qa/deleting-issues-with-jira-post-functions/, but I am having hard time adjusting it to my needs since it's about deleting current Issue.

If nobody can help with deletion of specific Sub-Task issue type, delete all Sub-tasks via Post Function in the current ticket would already help a lot! Anyone has experience with it?

Cheers,

Rok

3 answers

1 accepted

4 votes
Answer accepted
Thanos Batagiannis _Adaptavist_
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.
December 11, 2015

Hi Rok

The code below will DELETE ALL the subtasks of the parent issue. All the sub tasks have issue type SubTask therefore you have to find another condition in order to specify which you want to delete. For more information about the issue deletion functions: https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/IssueManager.html

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)
}

Hope that script gives you an idea

Kind regards,

Thanos

0 votes
Ewald_Ninaus May 10, 2016

I used the code for removing subtasks (same like https://www.adaptavist.com/doco/display/SFJ/Delete+all+subtasks+of+a+parent+issue+as+a+workflow+post+function), but I have the problem, that my Index isn't correct after deleting subtasks.

 

If I search for the Issue-Title (Summary), there is still an invalid result in the search-result.

So I have to start a manual Background reindex to get correct results.

 

Any Ideas?

Jens Goetz October 27, 2016

We have the same problem, using the following code to delete all subtasks of an issue:

Issue currentIssue = issue as Issue
Collection<Issue> currentIssueSubTasks = currentIssue.getSubTaskObjects()
if (currentIssueSubTasks) {
    ApplicationUser currentApplicationUser = ComponentAccessor.getJiraAuthenticationContext().getUser()
    User currentUser = ApplicationUsers.toDirectoryUser(currentApplicationUser)
    IssueService issueService = ComponentAccessor.getIssueService()
    for (currentIssueSubTask in currentIssueSubTasks) {
        DeleteValidationResult deleteValidationResult = issueService.validateDelete(currentUser, currentIssueSubTask.getId())
        if (deleteValidationResult.isValid()) {
            issueService.delete(currentUser, deleteValidationResult)
        } else {
            log.debug(deleteValidationResult.getErrorCollection())
        }
    }
}

SOMETIMES, the deleted subtasks are still visible on the agile boards and if you click on them you get a popup stating that "Error   Issue Does Not Exist"...

0 votes
Thanos Batagiannis _Adaptavist_
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.
December 11, 2015

Hi Rok, Which version of JIRA ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events