• Community
  • Questions
  • How to change the status of an epic when the stories chnge their status

How to change the status of an epic when the stories chnge their status

I'm trying to run a script listener that updates the status of the epic (not the EpicStatus custom field) when one of the stories change its status.
The case is I don't know which event should I listen. I tried to use a generic event, but I can't figure out how to get its name and if I don't set any condition the event name, it runs a lot of times and breaks. How do I get the name of a generic event?
PS: I'm not sure my script works too.
PSS: Here's my script. I've found it on the internet and adapted for my needs.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.customfields.option.Options;
import com.atlassian.jira.issue.customfields.option.Option;
import com.atlassian.jira.issue.fields.config.FieldConfig;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.user.ApplicationUser;
import com.opensymphony.workflow.loader.ActionDescriptor;
import com.atlassian.jira.workflow.JiraWorkflow;
import com.atlassian.jira.workflow.WorkflowManager;

ComponentManager componentManager = ComponentManager.getInstance();
def groupMan = ComponentAccessor.getGroupManager()
def authCon = ComponentAccessor.getJiraAuthenticationContext()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder();
IssueManager issueManager = ComponentAccessor.getIssueManager();
OptionsManager optionsManager = componentManager.getComponentInstanceOfType(OptionsManager.class);
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
String currentEpicStatus = "";

def curUser = authCon.getLoggedInUser()
def issue = event.issue

//this was a try of getting the name of the generic event, but it show the class name
if (event == "In Progress (21)") {
log.warn "In Progress (21)"
} else {
log.warn event.toString()

def epicLinkCf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}
if(!epicLinkCf) {log.warn "No Epic Link field"; return}
log.warn "Existing Epic Link: ${epicLinkCf.getValue(issue)}"

String epicIssue = epicLinkCf.getValue(issue)
Issue epic = issueManager.getIssueObject(epicIssue) // epicKey is passed into your script

// Check if Epic link is exist
return true

def newEpicState = "Done"

log.warn "Epic: " + epic
List<IssueLink> allOutIssueLink = issueLinkManager.getOutwardLinks(epic.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
log.warn "child link type: " + issueLink.getIssueLinkType().getName()
Issue chIssue = issueLink.getDestinationObject();
// Check status of all issues from epic
if (issueLink.getIssueLinkType().getName() == "Epic-Story Link") {
log.warn "child state: " + chIssue.getStatus().getName()
if(chIssue.getStatus().getName() == "In Progress") {
newEpicState = "In Progress"
} else if (chIssue.getStatus().getName() != "Closed" && newEpicState != "In Progress") {
newEpicState = "To Do"
} else if (issueLink.getIssueLinkType().getName() == "Epic Link") {
currentEpicStatus = chIssue.getStatus().getName();

log.warn "Current epic status: " + currentEpicStatus

log.warn "New epic status: " + newEpicState

// Set new status if it necessary
if (currentEpicStatus != newEpicState) {

WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager();
JiraWorkflow jiraWorkflow = workflowManager.getWorkflow(issue);
Collection<ActionDescriptor> cActionDesc = jiraWorkflow.getAllActions();
int actionId = 0;

for (ActionDescriptor res : cActionDesc) {
if (res.getName().equals(newEpicState)) {
actionId = res.getId();

IssueService issueService = ComponentAccessor.getIssueService();
IssueService.IssueResult transResult;

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();

TransitionValidationResult validationResult = issueService.validateTransition(curUser, issue.getId(), actionId, issueInputParameters);

if (validationResult.isValid()) {
transResult = issueService.transition(curUser, validationResult);

log.warn "Epic status is updated!"


0 answers

Suggest an answer

Log in or Join to answer
Community showcase
Jason Wong
Published yesterday in Agility Beta

Welcome to agility

Every team in the world is unique, and so   Atlassian believes   that each and every team's best way of working  needs to  be molded to their unique circumstances  – ...

352 views 6 15
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot