Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Moving subtask issue type together with parent issue type

Valentina Benedetto
Contributor
September 11, 2020

Good day,

I am trying to find a way to move automatically the issue type of all the subtasks while moving parent issue type.

Lets say we have a "Task" issue with a subtask "Task-subtask" and then we move the parent issue to "Bug" and I want subtask to automatically change to "Bug-subtask" 

I am trying to add the following code in the additional issue action under the Fast-track transition an issue Listener which listens to the parent issue type move (this listener works well and changes the status of the parent issue):

import com.atlassian.jira.component.ComponentAccessor

def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def subTasks = issue.getSubTaskObjects()
subTasks.each {
def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="Bug- Sub-Task"}
if (newIssueType) issue.setIssueTypeObject(newIssueType)}

with the condition like this: 

def types = ['Bug']
issue.issueType.name in types

But it fails :(

I tried to add this code as postfunction on the parentissue transition but then it changes the issue type of parent issue to Bug-subtask 

I am all new to Scriptrunner. Trying to figure our what might be the case here. Will be happy to hear any advices, thanks in advance :) 

1 answer

0 votes
Gustavo Félix
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.
September 11, 2020

Hi @Valentina Benedetto 
Based on this code and If I  understood right...

if (newIssueType) issue.setIssueTypeObject(newIssueType)}

Here you are setting the Issue type of issue to "bug sub-task".
The way I see it , you should do this with the subtasks you are iterating.

Am I right?

Valentina Benedetto
Contributor
September 14, 2020

Hi Gustavo, do you know how should I change it to do it with subtasks? 

Shall I change it to 

if (newIssueType) Subtask.setIssueTypeObject(newIssueType)} ?

Gustavo Félix
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.
September 15, 2020

Based on your code , you could try it like that.

subTasks.each { subtask->

def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="Bug- Sub-Task"}
if (newIssueType) subtask.setIssueTypeObject(newIssueType)}

I dont have the "setIssueTypeObject" method, so I used inputParameters instead.

IssueInputParameters inputParameters = issueService.newIssueInputParameters()
def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="Bug- Sub-Task"}
if(newIssueType){
subTasks.each { subtask->
inputParameters.setIssueTypeId(newIssueType.id)
IssueService.UpdateValidationResult validationResult = issueService.validateUpdate(user,subtask.id,inputParameters)
issueService.update(user,validationResult)
}
}

Suggest an answer

Log in or Sign up to answer