Forums

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

Possible to update the status of sub-task if parent task status changes?

rajey March 10, 2020

Hi,
I'm new to Jira.
I'm trying to update the status of the sub-task if the parent task changes status to "NR".
All of the workflows have an "Not Required" (not required state). 

This is what I have currently tried, however the project is not updated.

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.status.Status
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption

IssueManager im = ComponentAccessor.getIssueManager();
def GroupManager = ComponentAccessor.getGroupManager();
UserManager userManager = ComponentAccessor.getUserManager();
MutableIssue issue = im.getIssueObject("TEST-54");
long project_id = issue.getProjectId();

def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

def cStatus = issue.getStatus().getName();
def subIssueList = issue.getSubTaskObjects();
MutableIssue subIssue = null;
List subTaskStatus = [];
if(issue.getStatus().getName() == "Not Required"){
subIssueList.each {
it.getStatus().getName();
subIssue = im.getIssueObject(it.getKey());
subIssue.setStatus(issue.getStatus());
subTaskStatus.add(subIssue.getStatus().getName());
im.updateIssue(loggedInUser, subIssue, EventDispatchOption.DO_NOT_DISPATCH, false);
}
}

return subTaskStatus

 All of the sub-tasks are show "Not Required" when printing the information in console, however they are not updated under projects.

What do I need to add to save the changes?
And is it possible to automate this for any generic issue/project/workflow?

2 answers

0 votes
Taranjeet Singh
Community Champion
March 27, 2020

Hi @rajey your use case can be implemented in JIRA using one of the 3-rd party add-ons available in Atlassian Marketplace for that. If you don't have a strict requirement of sticking to this Groovy Code based automation, there are other 3-rd party add-ons that can be used to implement this automation without requiring any code. One of them is "Update on Transition for Jira". Please check out this add-on and its documentation on Atlassian Marketplace.

Hope it helps!

0 votes
rajey March 16, 2020
def transitionValidate = ComponentAccessor.getIssueService().validateTransition(User, pIssue.getId(), transitionId, new IssueInputParametersImpl());
if(transitionValidate.isValid())
{
def transition = ComponentAccessor.getIssueService().transition(User, transitionValidate);
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events