Last active
September 26, 2019 11:26
-
-
Save cben0ist/1ea6304b8b1e941695cb to your computer and use it in GitHub Desktop.
Jira script runner : change task to SubTask and link to parent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.atlassian.jira.component.ComponentAccessor | |
import com.atlassian.jira.ComponentManager | |
import com.atlassian.jira.security.Permissions | |
import com.atlassian.jira.event.type.EventDispatchOption | |
import com.atlassian.jira.user.ApplicationUser; | |
import com.atlassian.jira.issue.MutableIssue; | |
import com.atlassian.jira.issue.UpdateIssueRequest; | |
//Examples, 5 is my subtask issue type id. Will be different for others. Can find it in the issue history tab after converting a task to a sub-task | |
changeToSubTaskAndLink("XXX-8889", "XXX-0000", "5") | |
//Method to do all the work | |
def changeToSubTaskAndLink(parentId, childId, subTaskIssueTypeId) | |
{ | |
//Get the parent Issue | |
def parent = ComponentManager.getInstance().getIssueManager().getIssueObject(parentId) | |
//Get the child Issue | |
def child = ComponentManager.getInstance().getIssueManager().getIssueObject(childId) | |
//Change the child to the subtask type | |
child.setIssueTypeId(subTaskIssueTypeId) | |
//Update the issue | |
ComponentAccessor.getIssueManager().updateIssue((ApplicationUser)ComponentManager.getInstance().jiraAuthenticationContext?.user, | |
(MutableIssue)child, | |
UpdateIssueRequest.builder().build()) | |
//Create the subtask link, if this is not done you'll end up with orphans | |
ComponentAccessor.getSubTaskManager().createSubTaskIssueLink(parent, | |
child, | |
ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I need something similar to this but in my case.. I want to move subtasks from one parent to the other