Forked from cben0ist/JIRA changeToSubTaskAndLink.groovy
Created
May 27, 2016 14:29
-
-
Save two7sclash-zz/73ed401776148145af0f4dab5bb3b926 to your computer and use it in GitHub Desktop.
Jira script runner : change task to SubTask and link to parent
This file contains 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