Forums

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

ScriptRunner Need to grab all subtasks of a story

Aishwarya Rajan March 23, 2018

i tried the following code but seems 

ComponentManager.getInstance().getSubTaskManager(); is not supported in the jira version that Iam using and is saying that method does not exist. below is the code:

 

import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue

def myIssue = event.issue
if (myIssue.getIssueType().getName() == "Story"){
if(myIssue.getStatus().getName() == "In Progress"){
SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
Collection subTasks = myIssue.getSubTaskObjects()
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each {

}
}

}
}

 

any leeds reg the same???

3 answers

2 accepted

3 votes
Answer accepted
Alexey Matveev
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 23, 2018

Try like this

import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue


def myIssue = event.issue
if (myIssue.getIssueType().getName() == "Story"){
if(myIssue.getStatus().getName() == "In Progress"){
SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
Collection subTasks = myIssue.getSubTaskObjects()
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each {

}
}

}
}
Aishwarya Rajan March 23, 2018

yup figured it out..! thanks @Alexey Matveev

1 vote
Answer accepted
Ivan Tovbin
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 23, 2018

What is your Jira version?

If it's 7.x then to get and instance of SubTaskManager try this:

import com.atlassian.jira.component.ComponentAccessor

def subTaskManager = ComponentAccessor.getSubTaskManager()
Aishwarya Rajan March 23, 2018

yup figured it out..! thanks @Ivan Tovbin

0 votes
Aishwarya Rajan March 23, 2018

hey @Alexey Matveev @Ivan Tovbin  i tried this..and I had to change the status of subtask to done.

 

SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
Collection subTasks = myIssue.getSubTaskObjects()
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each {
if(it.getIssueType() == "Sub-task"){
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);
workflowTransitionUtil.setIssue(it); ---------------------------------error
String subTaskStatus = it.getStatus().getName().toString()
if(!(subTaskStatus.equals("Done"))){
workflowTransitionUtil.setAction(91);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
}
}
}
}

 

it shows error in this line workflowTransitionUtil.setIssue(it);  saying cannot find matching method..any leads on this..I have done thise before in many cases but facing error in this line seems strange..

Alexey Matveev
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 23, 2018

Your code must be like this

 

import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl



SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
Collection<Issue> subTasks = myIssue.getSubTaskObjects()
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each {
if(it.getIssueType() == "Sub-task"){
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);
workflowTransitionUtil.setIssue((MutableIssue) it);
String subTaskStatus = it.getStatus().getName().toString()
if(!(subTaskStatus.equals("Done"))){
workflowTransitionUtil.setAction(91);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
}
}
}
}

the myIssue variable must be of MutableIssue type.

Aishwarya Rajan March 26, 2018

hi @Alexey Matveev  I tried using this code, but seems the getIssueType()  method is not working..is there any other alternative instead of getIssueType(). can I use getIssueType.getName()??? I need to check if the issue is a Story first and later if that Story issue has child sub task issues...any leads on this?

 

def myIssue = event.issue
if (myIssue.getIssueType() == "Story"){
if(myIssue.getStatus().getName() == "In Progress"){
// UserMessageUtil.success(""+event)

SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
Collection<Issue> subTasks = myIssue.getSubTaskObjects()
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each {
if(it.getIssueType() == "Sub-task"){
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);
workflowTransitionUtil.setIssue((MutableIssue) it);
String subTaskStatus = it.getStatus().getName().toString()
if(!(subTaskStatus.equals("Done"))){
workflowTransitionUtil.setAction(91);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
}
}
}
}
}
}

Alexey Matveev
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 26, 2018

You should learn how to search the Jira Java Api. If you find the Issue class, then you will see, that issue.getIssueType returns IssueType object and that is why you are completly right you have to use 

it.getIssueType().getName()

If you are not sure about any value in your script, you can use

log.error(variableName) 

Suggest an answer

Log in or Sign up to answer