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.
Hi @Stephen Higgins Try use subtaskManager.changeParent method.
You can test this example script via Script Console:
import com.atlassian.jira.component.ComponentAccessordef issueManager = ComponentAccessor.issueManagerdef subtaskManager = ComponentAccessor.subTaskManager//get old parent issuedef oldParentIssue = issueManager.getIssueObject("AA-338")//get new parent issuedef newParentIssue = issueManager.getIssueObject("AA-339")//get old parent subtasksdef subtasks = oldParentIssue.getSubTaskObjects()//logged in userdef currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()subtasks.each { child ->//update all subtasks to a new parent issuesubtaskManager.changeParent(child, newParentIssue, currentUser)}
Another example, if run in the post-function:
import com.atlassian.jira.component.ComponentAccessordef issueManager = ComponentAccessor.issueManagerdef subtaskManager = ComponentAccessor.subTaskManager//get new parent issuedef newParentIssue = issueManager.getIssueObject("AA-339")def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()if(issue.subTask){ subtaskManager.changeParent(issue, newParentIssue, currentUser)}
I hope this helps.
@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
It looks like you're new here. Sign in or register to get started.