Finding epics with tasks in certain states
Asked by Luciano Moretti:

In our epics we have tasks where both need to be done before we can move the ticket forward but the tasks are done by different groups. Sometimes the other team gets their task done and the other doesn't for a while. I'd like to prioritize tickets where half the ticket has moved forward to speed up our ticket flow.

Ideally, in English, I want to find the following:  

Epics with a task who's title includes the word "TeamA" and is in the state "ToDo" that also have a task who's title includes the word "TeamB" and is in the state "Done"

So far my searching and ChatGPT have struck out on a way to do this.


Answers:
author: Luciano Moretti
body: Here's how I finally did it:  

I used the Jira API Python package.

I ran two queries, made a list of parent keys, then made another list with just the duplicate keys.

```
from jira import JIRA as Jira

# Function for getting the full list using multiple queries.
def get_jira_issues(jira, jql_query):
    start = 0
    limit = 50
    issue_list = []

    while True:
        issues = jira.search_issues(jql_query, startAt=start, maxResults=limit, fields='parent')#, fields=["summary","status", "labels", "priority"])
        issue_list.extend(issues)
        if len(issues) < limit:
            break
        start = start + limit
    return issue_list


teama_query = 'project = MYPROJECT AND status IN ("Draft","To Do") AND summary ~ "TeamA"'
teamb_query = 'project = MYPROJECT AND status = "Done" AND summary ~ "TeamB"'

j = Jira(server='https://MYDOMAIN.atlassian.net/',basic_auth= (USERNAME, API_KEY)

issues = get_jira_issues(j, teama_query)

for i in issues:
    teama_parents = [issue.fields.parent.key for issue in issues]

issues = get_jira_issues(j, teamb_query)

for i in issues:
    teamb_parents = [issue.fields.parent.key for issue in issues]

common = [ticket for ticket in teama_parents if ticket in teamb_parents]

print(f"Common Epics: {common}")
```


author: Trudy Claspill
body: Hello [@Luciano Moretti](/t5/user/viewprofilepage/user-id/5530965)

Welcome to the Atlassian community.

What do you want as output? Would that be a list of Epics?

Do you have any JQL extending apps like ScriptRunner Enhanced Search or JQL Search Extensions?

What you are requesting cannot be done with the native issue filtering capabilities, but can be done if you have an appropriate JQL extending app.

comments: author: Luciano Moretti
body: [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)   

Thank you for your response:  
Yes, the output I'd like is a list of Epics that match the criteria.  

I don't have any JQL Extending Apps and I'm doubtful that my business would be willing to pay the licensing costs associated just for me to use them.

It is frustrating that Jira can't do a query of this sort natively. It seems like being able to get information about the state of tasks under an epic should be base functionality.


author: Trudy Claspill
body: Hello [@Luciano Moretti](/t5/user/viewprofilepage/user-id/5530965)

You could do a work around with an Automation Rule.

Automation rules can be created by Jira Administrators. Jira Admins may also grant permission to create automation rules to other users that are only Project Administrators. If so, those Project Admins can create rules that run against the issues in just one project at a time (vs. Jira Admins who can create rules that look at issues in multiple projects at once).

There are a couple of different ways that a rule might be constructed for this. The end result would be to send an email for each Epic that met your conditions.

The rule could be scheduled to run periodically. It could be set to initially select a generalized set of Epics to review based on criteria applied directly to the Epics, such as *statusCategory!=Done*

You could then use Conditions to see if the Epic has children that match your criteria, and then send an email if the Epic does.

![Screenshot 2024-06-27 at 11.37.34?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/332246iC56D1A03BB9B48AE/image-size/large?v=v2&px=999 "Screenshot 2024-06-27 at 11.37.34?AM.png")


Tags: cloud

jira-cloud

jql