Filter for custom fields of Epic and Task
Asked by Pauline Hild:

Hello all,  
I would like to create a filter that uses custom fields as search criteria both at the level of tasks and epics. However, so far the filter does not work once I add the custom field of the Epic.

<br />

The screenshot shows the current syntax.

For example, "Technology: llumina_PCR-free_tagmentation" is a custom field of the task and "Account information: yes" is a custom field of the corresponding epic.

![Bildschirm?foto 2022-11-23 um 11.25.23.png](/t5/image/serverpage/image-id/227205i60B3D9D9D19861B8/image-size/large?v=v2&px=999 "Bildschirm?foto 2022-11-23 um 11.25.23.png")

Does anyone know a solution for this problem?

<br />

Best regards

Pauline


Answers:
author: Trudy Claspill
body: Hello [@Pauline Hild](/t5/user/viewprofilepage/user-id/4773022)

When you use the AND operator, every issue in the result set has to satisfy ALL the conditions you specify. So all your issue types must have all these fields and match the criteria.

If some fields are available for only some issue types then you need to use an OR operator.

Lets say some fields are in both issues types:

Field1 is in Epics and Tasks

Field2 is in only Epics

Field3 is in only Tasks

If you want to find all Tasks and Epics that have Field1=Value1, but also limit the results to Epics where Field2=Value2 and Tasks where Field3=Value3 then your filter would look like this.

```
Field1=Value1 and ( (issueType=Epic and Field2=Value2) or (issueType=Task and Field3=Value3) )
```

For more information take a look at

<https://support.atlassian.com/jira-software-cloud/docs/what-is-advanced-searching-in-jira-cloud/#Advancedsearching-ConstructingJQLqueries>

comments: author: Pauline Hild
body: Hello Trudy,

thanks for your help!


author: Pauline Hild
body: I changed the syntax as you suggested, but always get an error message. I have tried several changes but can't find the error. Do you have any idea?

![Bildschirm?foto 2022-11-26 um 15.26.20.png](https://community.atlassian.com/t5/image/serverpage/image-id/227654i2490A968004E2214/image-size/large?v=v2&px=999 "Bildschirm?foto 2022-11-26 um 15.26.20.png")


author: Trudy Claspill
body: "issue type" needs to be one word with no space - "issuetype"


author: Pauline Hild
body: OK, thanks so far. I changed it, but there still seems to be an error...

![Bildschirm?foto 2022-11-27 um 12.19.45.png](https://community.atlassian.com/t5/image/serverpage/image-id/227678iD37C8F704F835107/image-size/large?v=v2&px=999 "Bildschirm?foto 2022-11-27 um 12.19.45.png")


author: Trudy Claspill
body: I recommend that you try smaller pieces of the query to find which piece has the error.

The pieces related to standard Jira entities (project, issuetype, status) appear to be correct. That suggests to me that there is something wrong with one of the criteria associated with your custom fields:

* "Go for library"
* "Technologie\[Dropdown\]"
* "Account information\[Dropdown\]"

The syntax for the dropdown fields appears to also be correct.

Do all of those custom fields exist in the LAB project for the specified issue types?

What type of field is "Go for library"? If you try just that criteria do you get the bad syntax indicator?

```
project = LAB and "GO for library" is not EMPTY
```

You could check each of the other criteria individually to see if they are valid syntax also, and start adding more pieces to figure out which is the problem. For example start with

```
project = LAB and ((issuetype = Task) or (issuetype = Epic))
```

Then start adding the other criteria in one at a time until you trigger the bad syntax indicator.


author: Pauline Hild
body: Thank you very much for your detailed answer. I have actually found the solution this way.

But the filter does not yet work as I would like it to. At the moment it shows me the correct tasks, but also all epics where the "Account information" is filled in with "yes".

However, I only want to filter for those tasks where the linked Epic has "yes" as "Account information", i.e. the Epics should not be displayed but only the tasks whose linked Epic has that.

<br />

Can I include this in the syntax?


author: Trudy Claspill
body: Please show us the filter you are using now that is not getting you the results you want.


author: Pauline Hild
body: Sorry, I forgot to attach the screenshot.

![Bildschirm?foto 2022-12-05 um 10.32.44.png](https://community.atlassian.com/t5/image/serverpage/image-id/228986i638B0346273A1085/image-size/large?v=v2&px=999 "Bildschirm?foto 2022-12-05 um 10.32.44.png")


author: Trudy Claspill
body: Natively Jira allows you to search for Tasks in Epics only if you provide an explicit list of Epic Issue Keys thus:

<https://support.atlassian.com/jira-software-cloud/docs/advanced-search-reference-jql-functions/#Advancedsearchingfunctionsreference-parentepicparentEpic-->

```
Project = Lab and parentEpic(<comma separated list of Epic issue keys>) and issuetype = Task and?status in (?In Progress?) and??Go for library[Date]? IS NOT EMPTY and??Technologie[Dropdown]? = Illumina_PCR-free_tagmentation
```

You are trying to create a dynamic list of Epics from which to get Tasks. That is not supported natively in Jira search functionality.

To achieve that you would need a third party app that extends JQL capabilities. There are several available.

One that I have used is [Adaptavist Scriptrunner](https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?hosting=cloud&tab=overview). If you had that then you could achieve your goal thus:

```
Project = Lab and issuefunction in issuesInEpics(project=LAB and ?Account information[Dropdown]? = yes) and issuetype = Task and?status in (?In Progress?) and??Go for library[Date]? IS NOT EMPTY and??Technologie[Dropdown]? = Illumina_PCR-free_tagmentation
```


author: Pauline Hild
body: I was not aware of that, thanks for the info.

I had thought of another way that I could possibly solve my problem, however I'm not sure if that would work.

I also added the "Account information" field to the task layout and set up an automation rule so that the info entered in this field is transferred from Epic to the task.

Accordingly, I have adjusted the syntax so that "Account information" is now a field of the task.  
So far, however, the filter does not work, because no results are found. Is this not possible in principle?

![Bildschirm?foto 2022-12-06 um 16.25.31.png](https://community.atlassian.com/t5/image/serverpage/image-id/229144iD11C9312D7AE3588/image-size/large?v=v2&px=999 "Bildschirm?foto 2022-12-06 um 16.25.31.png")


author: Trudy Claspill
body: In principal this should work.

Are you sure that the field is getting transferred from the Epic to the Tasks?

Since you have removed the clause that concerned Epics you don't actually need the "((" and "))" anymore. Try removing those and see if the results change.

Try running a search for the original Task criteria (without Account Information) and then visually review the issues to confirm that one of them has the Account Information set to "yes".


author: Pauline Hild
body: I think I have found the problem. The newly created automation takes the information from the "Account information" field from Epic into the task, but only for projects that are now newly created and not for already existing projects. Therefore the "Account information" field is not filled in for the older projects and the filter does not show any results.  
To solve this problem, I guess I'll have to resort to the app.


author: Trudy Claspill
body: You said
> I also added the "Account information" field to the task layout and set up an automation rule so that the info entered in this field is transferred from Epic to the task.

You can use a rule to update the older issues also. I don't know what you have for the above rule, but you can create a rule that you trigger manually that will look up all the tasks that have no value in that field and then get it from their parent Epic.

There is a limit to the number of issues a rule can operate against in a single run, so if there are hundreds of issues you may need to run the rule a few times or refine the look up to get a smaller set of issues.


author: Pauline Hild
body: I didn't know there was such a function, that would be very helpful not only in this context. What would the automation rule look like then?

<br />

On the screenshot below is my automation that takes the info from the Epic into the task. With newly created projects this already works.

![Bildschirm?foto 2022-12-08 um 14.52.01.png](https://community.atlassian.com/t5/image/serverpage/image-id/229610iB4865D6F094BBDE4/image-dimensions/246x362?v=v2 "Bildschirm?foto 2022-12-08 um 14.52.01.png")![Bildschirm?foto 2022-12-08 um 14.52.08.png](https://community.atlassian.com/t5/image/serverpage/image-id/229611i0C309306595F27E9/image-dimensions/362x250?v=v2 "Bildschirm?foto 2022-12-08 um 14.52.08.png")


Tags: cloud