Forums

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

Jira Cloud - Script Runner Cloud - Change Parent Issue status based upon subtask status

Jan Otterstetter
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 14, 2018

Hi,

while workflow transition of a subtask I want to change the parent issues status based upon the subtask status.

Therefore I installed Adaptavist Scriptrunner plugin and wrote the following code I based on several examples in the community:

 


import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.comments.CommentManager;
import com.opensymphony.workflow.WorkflowContext;
import org.apache.log4j.Category;
import com.atlassian.jira.config.SubTaskManager;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;


// get currentUser context
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();

// get workflow context
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);

// get parent issue
def parent = ComponentAccessor.getIssueManager().getIssueObject(issue.getParentId());

// get parent issue status
String currentParentStatus = parent.getStatus().getSimpleStatus().getName();
String currentParentStatusId = parent.getStatusId();
def parentNotDoneYet = currentParentStatus in ['BACKLOG', 'SPECIFICATION', 'REVIEW'];

// if parent is not done yet fetch subtasks
if (parentNotDoneYet) {

// get subtasks of parent
SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
Collection subTasks = parent.getSubTaskObjects();
boolean transitionParent = false;
String transitionToStatusId = 0;

if(subTaskManager.subTasksEnabled){
String previousSubtaskStatus = "#";
String statusReviewId = 0;

for(subtask in subTasks){
String status = subtask.getStatus().getSimpleStatus().getName();
String statusId = subtask.getStatusId();

if( previousSubtaskStatus == "#"){
previousSubtaskStatus = status;
}

if ( !transitionParent && currentParentStatus != status && status == 'BACKLOG') {
transitionParent = true;
transitionToStatusId = statusId;
}
else if( !transitionParent && currentParentStatus != status && status == 'SPECIFICATION') {
transitionParent = true;
transitionToStatusId = statusId;
}
else if( !transitionParent && currentParentStatus != status && status == 'REVIEW') {
transitionParent = true;
transitionToStatusId = statusId;
statusReviewId = statusId;
}
else if( !transitionParent && currentParentStatus != status && status == 'DONE') {
transitionParent = true;
transitionToStatusId = statusReviewId;
}
}

if(transitionParent){
workflowTransitionUtil.setIssue(parent);
workflowTransitionUtil.setUserkey(currentUser);
workflowTransitionUtil.setAction(transitionToStatusId);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
}

}

}

 

Issues

Executing the above code in the Scriptrunner console gives me the following errors (I don't know Groovy)

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 10: unable to resolve class com.atlassian.jira.issue.MutableIssue @ line 10, column 1. import com.atlassian.jira.issue.MutableIssue;

^ Script1.groovy: 3: unable to resolve class com.atlassian.jira.issue.comments.CommentManager @ line 3, column 1. import com.atlassian.jira.issue.comments.CommentManager;

^ Script1.groovy: 4: unable to resolve class com.opensymphony.workflow.WorkflowContext @ line 4, column 1. import com.opensymphony.workflow.WorkflowContext;

^ Script1.groovy: 9: unable to resolve class com.atlassian.jira.util.JiraUtils @ line 9, column 1. import com.atlassian.jira.util.JiraUtils;

^ Script1.groovy: 2: unable to resolve class com.atlassian.jira.ComponentManager @ line 2, column 1. import com.atlassian.jira.ComponentManager;

^ Script1.groovy: 7: unable to resolve class com.atlassian.jira.workflow.WorkflowTransitionUtil @ line 7, column 1. import com.atlassian.jira.workflow.WorkflowTransitionUtil;

^ Script1.groovy: 8: unable to resolve class com.atlassian.jira.workflow.WorkflowTransitionUtilImpl @ line 8, column 1. import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;

^ Script1.groovy: 6: unable to resolve class com.atlassian.jira.config.SubTaskManager @ line 6, column 1. import com.atlassian.jira.config.SubTaskManager;

 

How needs the script to look like to

1. execute it in Jira cloud Scriptrunner console

2. execute it in Jira cloud workflow Post-Function script

 

Thanks for helping out.

Best regards

Jan

1 answer

0 votes
Pallavi Prashant Yewale
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 18, 2018

What is the difference between Jira cloud Scriptrunner and ScriptRunner for Jira. I am executing this code in Scriptrunner console but getting same errors - 

startup failed:
Script1.groovy: 1: unable to resolve class com.atlassian.jira.workflow.WorkflowTransitionUtil
 @ line 1, column 1.
   import com.atlassian.jira.workflow.WorkflowTransitionUtil;

Suggest an answer

Log in or Sign up to answer