JQL Query to get issues with attachments

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?

3 answers

1 accepted

Accepted Answer
2 votes

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.

For the current JIRA Cloud version this seems to work:

attachments IS NOT EMPTY

You're welcome.

0 votes

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.

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.

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

JQL query is: issue in hasAttachments()

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

22,423 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you