Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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 Leader Mar 27, 2020

Hi @kingYR 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!

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

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you