JQL Query to get issues with attachments

SuhailM March 20, 2013
JqlClauseBuilder builderAllIssues = JqlQueryBuilder.newClauseBuilder();
		JqlClauseBuilder tempQueryAllIssues = builderAllIssues.project(specifiedProject.getId());
		Query queryAllissues = tempQueryAllIssues.buildQuery();
		SearchResults searchResultsAllIssues = searchProvider.search(queryAllissues, specifiedProject.getLead(), PagerFilter.getUnlimitedFilter());
		List<Issue> allIssues = searchResultsAllIssues.getIssues();

The above JQL builder query returns all issues. But, my requirement is to return issues who have attachements only.Is there any way i can get issues with attachments by modifying this query?

5 answers

1 accepted

3 votes
Answer accepted
MJ
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 20, 2013

I have never been able to get a JQL working to filter issues that have attachments. As a workaround, I add the "number of attachments" field and from there exclude all issues that have 0 as value for that field.

3 votes
Tom_Hundt May 23, 2020
Paras Sharma April 24, 2021

works!!!Thx

3 votes
Max Fuxjäger February 6, 2018

For the current JIRA Cloud version this seems to work:

attachments IS NOT EMPTY

You're welcome.

1 vote
JamieA
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.
March 20, 2013

Not by modifying that query directly, but you can use hasAttachments() function from the script runner plugin.

You have to reindex after installing the plugin for that function to work, but that is also true if you add the "number of attachments" field as Mick suggests.

Note that using this function is much quicker than checking each issue for attachments.

SuhailM March 20, 2013
What i dint understand is "number of attachments" field.Is this some kind of cutom field i need to create or something is avaialbe in JIRA.How can i incorporate this field in the below JQL query...
SearchResults searchResultsAllIssues = searchProvider.search(queryAllissues, specifiedProject.getLead(), PagerFilter.getUnlimitedFilter());
List<Issue> allIssues = searchResultsAllIssues.getIssues();
----------------------------------------------------------
I will be gratefull if you share some code which has implmented this scenario.
Thanks.
JamieA
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.
March 20, 2013

it's in jira suite utils or jira toolkit IIRC.

Alex Tabrizi May 18, 2016

JQL query is: issue in hasAttachments()

You can also read this page to learn more: http://www.j-tricks.com/jqlt-issue-functions.html

0 votes
Muhammad Akram Sharifi May 8, 2021

Project = ABCD AND attachment is not EMPTY

will list for you the issue that their attachment is not empty.

Suggest an answer

Log in or Sign up to answer