JIRA JQL - Find all subtasks that are in X status, where the parent is in X status

Learn jira jql - find all subtasks that are in x status, where the parent is in x status with practical examples, diagrams, and best practices. Covers jira, jql development techniques with visual e...

JQL Deep Dive: Finding Subtasks with Parents in the Same Status

Jira JQL query interface with subtasks and parent issues highlighted

Master JQL to efficiently locate subtasks that share a specific status with their parent issues, streamlining your Jira workflow and reporting.

Jira Query Language (JQL) is a powerful tool for searching and filtering issues within Jira. While basic queries are straightforward, finding issues based on relationships between them, such as parent-subtask relationships, can be more complex. This article will guide you through constructing a JQL query to identify all subtasks that are in a particular status, where their respective parent issues are also in that exact same status. This is incredibly useful for scenarios like identifying stalled work, ensuring synchronization, or auditing specific workflow states.

Understanding Parent-Subtask Relationships in JQL

Jira issues can be linked in various ways, but the parent-subtask relationship is a fundamental hierarchy. Subtasks are directly associated with a single parent issue. JQL provides functions and operators to traverse these relationships. The key to our query lies in using the issueFunction with the parentsOf function, combined with a subquery to check the status of both the subtask and its parent.

flowchart TD
    A[Start JQL Query] --> B{Is current issue a Subtask?}
    B -- Yes --> C[Check Subtask Status (e.g., 'In Progress')]
    C --> D{Find Parent of Subtask}
    D --> E[Check Parent Status (e.g., 'In Progress')]
    E -- Both Match --> F[Include Subtask in Results]
    E -- Mismatch --> G[Exclude Subtask]
    B -- No --> G

Logical flow for identifying subtasks with matching parent status

Constructing the JQL Query

To achieve our goal, we need a query that first identifies all subtasks, then for each subtask, checks its status, and finally checks the status of its parent. The issueFunction with parentsOf is crucial here. We'll use a specific status, for example, 'In Progress', but you can replace this with any status relevant to your workflow.

issueType in subTaskIssueTypes() AND status = "In Progress" AND issueFunction in parentsOf("status = \"In Progress\"")

Let's break down this query:

  • issueType in subTaskIssueTypes(): This part ensures that we are only looking at issues that are subtasks. subTaskIssueTypes() is a JQL function that returns all issue types configured as subtasks in your Jira instance.
  • status = "In Progress": This filters the results to only include subtasks that are currently in the 'In Progress' status.
  • issueFunction in parentsOf("status = \"In Progress\""): This is the most critical part. The parentsOf() function takes another JQL query as its argument. It returns all issues that are parents of issues matching the inner query. In our case, the inner query "status = \"In Progress\"" checks if the parent issue is also in the 'In Progress' status. The outer issueFunction in then filters our initial set of 'In Progress' subtasks to only those whose parents also meet the 'In Progress' status criteria.

Adapting for Different Statuses or Custom Fields

This query is highly adaptable. You can easily change the status to any other status in your workflow, such as 'To Do', 'Done', 'Blocked', or custom statuses. You can also extend the inner query to include other criteria for the parent issue.

issueType in subTaskIssueTypes() AND status = "Blocked" AND issueFunction in parentsOf("status = \"Blocked\" AND assignee is not EMPTY")

In this example, we're looking for subtasks that are 'Blocked' AND whose parents are also 'Blocked' AND have an assignee. This demonstrates how you can add more conditions to the parent's criteria.

Practical Applications

This JQL query is invaluable for several use cases:

  • Workflow Synchronization: Identify subtasks that are moving ahead or lagging behind their parent's status, indicating potential workflow issues.
  • Reporting: Generate reports on specific work states where both parent and child are aligned, e.g., all 'Done' subtasks whose parents are also 'Done'.
  • Auditing: Ensure that critical parent issues are not left in a certain status while their subtasks are also in that status, potentially indicating a bottleneck or oversight.
  • Cleanup: Find subtasks that might be stuck in a status like 'In Progress' while their parent is also 'In Progress', helping to identify work that needs attention.