Tree queries and search

Tree queries pick rows by where they sit in a hierarchy. This page covers the language, query mode, finding a hierarchy's work items in Jira search, and the workflow rules built on it.

On this page

The tree query language

A tree query combines conditions about a row's kind, position and content, and it is not case sensitive.

Condition Picks
issues, folders, memos, plans, rules, groups, all Rows of that kind. Singular forms work too.
top Top-level rows.
leaves Rows with nothing under them.
key = PLAN-1, key in (PLAN-1, PLAN-2) Work items by key.
row = 12, row in (12, 13) Rows by number (see the Row ID column).
level <= 2 Rows by depth, with =, !=, <, <=, > or >=. The top level is 1.
jql "…" Work items matching a JQL query, asked of Jira with your own rights.
text "…" Rows whose text holds every word. The text of folders, memos, planning items and groups counts too.
children of …, parent of …, descendants of …, ancestors of …, siblings of … Rows related to what follows.

Combine conditions with not, and and or, in that order of precedence, and group them with parentheses. A relation applies to the condition right after it. Text takes double or single quotes, with \ to escape a quote.

Examples:

Query Finds
children of jql "issuetype = Epic" The rows directly under epics.
issues and descendants of key = PLAN-1 Every work item anywhere under PLAN-1.
leaves and not jql "statusCategory = Done" Rows at the bottom of the tree that are not done.
top and folders Folders at the top level.
children of (groups and text "Sam") The work items in a group named after Sam.

A query has at most 2,000 characters and 5 JQL conditions, and nests at most 32 levels deep (parentheses, relations and not each count as a level). When a query doesn't read, the message says what was expected and where. Jira checks each JQL part strictly first, so a misspelled field is an error instead of an empty result.

Example: what is still open under PLAN-1? PLAN-1 has the stories PLAN-2 (done) and PLAN-3 (open), a subtask PLAN-5 under PLAN-3 (open), and a folder called "Risks".

  1. At the right end of the toolbar, pick Tree query in the list beside the Find rows box.
  2. Type issues and descendants of key = PLAN-1 and not jql "statusCategory = Done".

You see PLAN-3 and PLAN-5, with PLAN-1 above them. PLAN-2 is done and the folder is not a work item, so neither matches.

Where tree queries work

  • Find rows: in Find, at the right end of the toolbar, choose Tree query in the list beside the search box. Matches update as you type. See Finding rows.
  • Transforms: Keep rows matching a tree query keeps the matches and the rows above them. See Transforms.
  • Columns: Matches a query… shows Yes or No for each row.
  • Formulas: TQL{leaves} is true on the rows that match. See Formulas.
  • Query mode, Jira search and workflow rules, below.

Query mode

Search work items, in the list on the left of the app's page, opens a temporary hierarchy from a query. Nothing is stored. Pick where to search with Search in:

  • Jira: type text, work item keys or JQL. Keys become a list of those work items, a JQL query is used as written, and other words are searched as text. An empty box shows the work items you viewed recently. Tick With child work items to bring in their children.
  • A hierarchy: pick a hierarchy and type a tree query. The matching rows open with the rows above them.

Select Show to run it. The result shows its first 500 rows and reads 500 more each time you scroll near the end. Columns, views, transforms, export and printing all work on it.

Save as hierarchy… keeps a Jira search as a new hierarchy made of rules, so it stays up to date. You can't save a tree query result this way, because a tree query isn't a rule. Open the hierarchy and use Find rows or a tree query transform instead.

People with Control can turn on Find its work items in Jira search on the Jira search tab of the hierarchy's settings. You can then find its work items anywhere Jira takes JQL, including work item search, filters, boards and dashboards:

issue in treecraftHierarchy(42)
issue in treecraftHierarchy("Product roadmap")
issue not in treecraftHierarchy(42)

The settings show the search by the hierarchy's number, which keeps working after a rename. Search by name works while the name is unique. The search finds the work items the hierarchy holds, whether someone placed them by hand or its rules placed them.

A second argument narrows the search to part of the tree, with a tree query:

issue in treecraftHierarchy(42, "children of key = PLAN-1")

In Jira search, a tree query may use only positions in the tree and work item keys: kinds, top, leaves, level, row, key and the relations. Jira search refuses jql and text conditions. A tree query names at most 50 work item keys, and a hierarchy keeps at most 10 different tree queries for search. People with Control see the tree queries people searched with, on the same tab, and can clear any of them. A saved filter that used a cleared query then says it was cleared.

Jira keeps search results for a while, so a change to the hierarchy can take a few minutes to show in search. A tree query used for the first time finds nothing until its work items are worked out, usually within a minute.

Example: a saved filter for the open work in a roadmap. You want a Jira filter that lists what is still open in "Product roadmap".

  1. Ask someone with Control to open the hierarchy's settings, go to the Jira search tab, and turn on Find its work items in Jira search.
  2. In Jira's work item search, switch to JQL and type issue in treecraftHierarchy("Product roadmap") AND statusCategory != Done.
  3. Save the filter.

You see the open work items of the hierarchy that you may browse. You can use the filter on a board or a dashboard. The name works while it is unique, so use the hierarchy's number if two hierarchies could share a name. A change to the hierarchy can take a few minutes to show.

What turning on search reveals

Anyone who can search Jira can use this search, including people who can't open the hierarchy. Jira still shows them only the work items they may browse, but they can tell that those work items are in the hierarchy and where they sit in it, and they can test work item keys they guess with a tree query. They never see the details of work items they can't browse. For this reason search is off until someone with Control turns it on, and the settings say so when you do.

Query troubleshooting

When a search finds less than you expect, open Help and select Query troubleshooting. Pick the hierarchy, type the tree query if there is one, and select Check. The page tells you:

  • the search to type in Jira;
  • whether search is on for the hierarchy, and whether the tree query reads correctly, with where it stops if it doesn't;
  • whether Jira search has used this tree query before, or whether it is new;
  • the JQL and work item keys the query uses.

Try it in Jira asks Jira, with your own rights, how many work items it finds. Anyone who can view the hierarchy can use this page. Jira admins and app admins also see how far the search index has come: how many work items the hierarchy holds, how many Jira search finds now, and how many are still to add or remove.

Workflow condition and validator

Jira admins can use a hierarchy in a workflow. Both rules are named Work item is in a hierarchy in Jira's workflow editor:

  • The condition shows a transition only for work items in, or not in, the chosen hierarchy. All it does is hide the transition.
  • The validator refuses the transition for work items that don't match and shows a message saying so. Add it when you want to enforce the rule.

Only hierarchies with Jira search turned on can be chosen. An optional tree query limits the rule to part of the hierarchy, with the same restrictions as in Jira search: positions and keys only, and at most 50 keys. While a hierarchy's search is off, no work item counts as in it. If someone with Control clears a tree query that a workflow rule uses, the validator refuses its transition until a Jira admin sets it up again. The hierarchy's settings mark such queries as Used by a workflow rule.

Questions about the app? Ask us in Plugincraft Support, our help center, or write to info@plugincraft.ca.