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 :)
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?
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)} ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.