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

This widget could not be displayed.

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.

This widget could not be displayed.

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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

578 views 25 15
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