Understanding the Filter Function:
The filter function in JQL allows you to reference and reuse saved filters. A saved filter is a predefined JQL query that in you or your team have created and saved for future use.
By using the filter function, you can incorporate these saved filters into new JQL queries, making your searches more modular and maintainable.
filter = "<filter name or ID>"
Here, <filter name or ID> refers to the name or ID of the saved filter you want to use.
Example 1: Using a Saved Filter by Name
Let’s say you have a saved filter named “High Priority Issues”. To use this filter in a JQL query, you would write:
filter = 12345
or
filter = “High Priority Issues” AND assignee = currentUser()
Use Case:
In one of the projects, I used filters to have the list of IDs against which I needed to filter the test cases.
issuetype = test execution and status not in (withdrawn) and (filter=15678 or filter=134567 or filter=137869 or filter=1968597)
This JQL filtered all the test execution which is part of the filters.
Creating complex JQL queries using the filter function involves combining multiple saved filters and additional JQL criteria to refine your search. Here are some examples that illustrate how you can build such complex queries:
1. Combining Multiple Filters
Scenario:
You have two saved filters:
- High Priority Bugs:
priority = High AND issuetype = Bug - Critical Tasks for Team A:
priority = Critical AND project = "Team A"
You want to find all issues that match either of these filters.
Complex Query:
(filter = "High Priority Bugs" OR filter = "Critical Tasks for Team A")
2. Adding Time-Based Criteria
Scenario:
You have a saved filter named “Open Issues” that shows all open issues. You want to find all open issues created in the last 7 days.
Complex Query:
filter = "Open Issues" AND created >= -7d
3. Combining Filters with Additional Criteria
Scenario:
You have a saved filter named “Sprint Issues” that shows all issues in the current sprint. You want to find all high-priority sprint issues assigned to the current user.
Complex Query:
filter = "Sprint Issues" AND priority = High AND assignee = currentUser()
4. Nested Filter References
Scenario:
You have multiple filters:
- Open Bugs:
status = Open AND issuetype = Bug - High Priority:
priority = High - Team A Issues:
project = "Team A"
You want to find high-priority open bugs assigned to Team A.
Complex Query:
filter = "Open Bugs" AND filter = "High Priority" AND filter = "Team A Issues"
5. Combining Filters with Sub-Queries
Scenario:
You have a saved filter named “Critical Issues” that shows all issues with critical priority. You want to exclude issues from a specific project “Project B” and also check if the issue has attachments.
Complex Query:
filter = "Critical Issues" AND project != "Project B" AND attachments IS NOT EMPTY
6. Using Function-Based Criteria with Filters
Scenario:
You have a saved filter named “Unresolved Issues” that shows all unresolved issues. You want to find all unresolved issues reported by the current user within the last month.
Complex Query:
filter = "Unresolved Issues" AND reporter = currentUser() AND created >= startOfMonth(-1)
7. Complex Query with Nested Conditions
Scenario:
You have a saved filter named “Team A High Priority” that includes high-priority issues for Team A. You want to refine this to only include issues that are either unresolved or due within the next 5 days.
Complex Query:
filter = "Team A High Priority" AND (resolution = Unresolved OR due <= 5d)
Best Practices:
- Name Your Filters Clearly: When creating saved filters, use clear and descriptive names. This makes it easier for you and your team to understand and reuse them.
- Keep Filters Up-to-Date: Regularly review and update your saved filters to ensure they remain relevant and accurate.
- Combine Filters Wisely: When combining filters with other criteria, make sure the resulting query is specific enough to return meaningful results.
- Use Filter IDs for Precision: If multiple filters have similar names, using the filter ID can help avoid confusion and ensure you’re referencing the correct filter.
- Testing: Test each part of your complex query separately to ensure accuracy before combining them.
- Documentation: Document your complex queries and the purpose of each saved filter used. This helps in maintaining and updating queries as needed.
Discover more from LR Virtual Classroom
Subscribe to get the latest posts sent to your email.