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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to change sub-task parentId using Groovy (Scriptrunner)

I am trying to change the parentId of a sub-task via a Groovy script in the Scriptrunner Console, but for some reason the change is not actually being saved.

Below, is the code I am using.

As you will see, I am getting the new parent from the change history of the sub-task, as it was moved by mistake. We have multiple cases like this, which is why I am trying to do this via a script.

Any help or guidance is appreciated.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.*
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils

def issueManager = ComponentAccessor.getIssueManager();
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)

final String issueKey = 'CLTAST-18782'
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issueKey)
def parent = ""

changeHistoryManager.getChangeItemsForField(issue, "Parent").each { def it -> parent = it.getFromString(); log.warn(it.getFromString()) }

if (issue.getParentObject().getKey() != parent){
log.warn ("Not the same parent")
def parentIssue = ComponentAccessor.issueManager.getIssueByCurrentKey(parent)
def parentId = parentIssue.getId()
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);

boolean wasIndexing = ImportUtils.isIndexIssues();
log.warn("Reindex issue ${issue.key} ${}")


1 answer

1 accepted

0 votes
Answer accepted

Sub-tasks are not linked to their containing issue by the parentID.  It's actually done with a hidden issue link type, but you don't need to worry about that directly.

Use SubTaskManager.changeParent(subtask, new parent, current user)

Thanks Nic, let me give that a try.

Can you share how to invoke it, and which package would need to be imported? I've actually never used this interface.

I found it on another thread, and was able to implement it and it worked perfectly.

Thanks again Nic.

From memory:

import com.atlassian.jira.config.SubTaskManager
def subTaskManager = ComponentAccessor.SubTaskManager
 subTaskManager.changeParent(issue, parentIssue, user)

Thanks Nic, I forgot to reply earlier

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events