JQL query to find all the child issues for a given parent whose custom field matches withe custom field of parent issue

Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2014

How can we write a jql query to find all the child issues for a structure whose custom field named area(example) matches with the custom field named area of the parent issue?

i have the following structure query to get all the child issues for a given parent issue. But how to add the extra part in the query to retrieve only those issues which are having the same value for a particular custom field like its parent?

issue in structure(Hierarchy, "descendant of PROJ-980")

 

 

2 answers

1 accepted

2 votes
Answer accepted
Igor Baltiyskiy December 11, 2014

if PROJ-980 has area X, you can say 

issue in structure(Hierarchy, "descendant of PROJ-980 and [area = X]")

Note, however, that in either S-JQL or in JQL you cannot express constrains on issues based on field values of other issues; you always need to name values directly. When designing S-JQL, we thought about including such constraints, but we decided not to because we lacked evidence that someone will need it. So far this is the first request of this kind.

As a workaround, if the field can have one of a few values, you can enumerate these values. For example, suppose that field area can only have three values: X, Y and Z; then you say

issue in structure(Hierarchy, "[area = X] and descendant of [area = X] OR
[area = Y] and descendant of [area = Y] OR
[area = Z] and descendant of [area = Z]
")

In case you need to find all descendants whose area > parents area, again, you'll need to name parent values directly:

issue in structure(Hierarchy, "[area > X] and descendant of [area = X] OR
[area > Y] and descendant of [area = Y] OR
[area > Z] and descendant of [area = Z]")

Edit: I've created a request in our JIRA for extending S-JQL to allow the mentioned constraints.


0 votes
Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 14, 2014

Thanks Igor that was very helpful. To add to the above query can we also perform search like this

in case i have a parent issue in structure of type "parent" and there are 4 subissues/descendants under it of type "sub" . Each of these issues have some area defined. i need to search all the subissues/descendants  whose area is greater than parent's area

so something like " find all descendants whose area > parents area"

Can we search in the existing S-JQL?

 

Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 14, 2014

I can understand from your comments "Note, however, that in either S-JQL or in JQL you cannot express constrains on issues based on field values of other issues; you always need to name values directly" but in case if we need to incorporate such criteria how can we do that?

Igor Baltiyskiy December 15, 2014

Again, you'll need to name the parent's area directly. So, if field {{area}} can only have values {{X, Y}} and {{Z}}, you'll need to do this: issue in structure(Hierarchy, "[area > X] and descendant of [area = X] OR [area > Y] and descendant of [area = Y] OR [area > Z] and descendant of [area = Z]")

Igor Baltiyskiy December 15, 2014

I've edited my answer to include this comment.

Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 15, 2014

Thanks Igor . Thanks a ton. That helped me. I have created few issues assigned the area and some of these issues are descendants of issue1 (descendant1,descendant2) and issue2 (descendant3,descendant4). Both issue1 and issue2 has area 10. So my query is: issue in structure("structure - 1" , " [area>10] and descendant of [area=10] ") So in case all these descendants have area > 10 , all the issues will be pulled out since both the parent issue had area 10. But if i want to restrict it to only one parent: issue in structure("structure - 1" , " [area>10] and descendant of [area=10] ") and and issue in structure(" structure - 1 ", "descendant of TESTNEW-785") This would work. But is there a better way of doing this.(restricting to some particular parent)

Igor Baltiyskiy December 15, 2014

Sure — you just need to substitute area constraint to issue key constraint: issue in structure("structure - 1", "[area > 10] and descendant of TESTNEW-785")

Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 15, 2014

Thank you Igor :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events