Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Change Parent ID for Sub-Task Post Function

Stephen Higgins September 21, 2020

I am having a tough time finding an example of how to do this, but I need to add a post function script for sub-task issue types that moves the current sub-task from the existing parent ID to a fixed parent ID.  Any help would be appreciated. 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
John Chin
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.
March 22, 2021

Hi @Stephen Higgins 

Try use subtaskManager.changeParent method.

You can test this example script via Script Console:

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.issueManager

def subtaskManager = ComponentAccessor.subTaskManager

//get old parent issue
def oldParentIssue = issueManager.getIssueObject("AA-338")

//get new parent issue
def newParentIssue = issueManager.getIssueObject("AA-339")

//get old parent subtasks
def subtasks = oldParentIssue.getSubTaskObjects()

//logged in user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

subtasks.each { child ->

//update all subtasks to a new parent issue
subtaskManager.changeParent(child, newParentIssue, currentUser)
}

Another example, if run in the post-function:

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.issueManager

def subtaskManager = ComponentAccessor.subTaskManager

//get new parent issue
def newParentIssue = issueManager.getIssueObject("AA-339")

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if(issue.subTask)
{
subtaskManager.changeParent(issue, newParentIssue, currentUser)
}

I hope this helps.

Bhupesh Nagda December 27, 2021

@John Chin 

Sorry to ask directly on this answer here, but would this work if new parent is from another project?so, is it possible to link to a parent on another project f.e. changing parent from AA-338 to BB-339

TAGS
AUG Leaders

Atlassian Community Events