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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

702 views 6 13
Read article

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