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

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.

0 vote

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

0 vote

For the current JIRA Cloud version this seems to work:

attachments IS NOT EMPTY

You're welcome.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,203 views 13 19
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot