Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Determine the Number of Projects with Attachments

Steven Janvrin
Contributor
May 31, 2023

Is there a way to modify the "attachments is not EMPTY" filter to return the projects that have attachments? The filter above works fine, but it returns all issues with an attachment, which for our Jira implementation is over 170K. We have less than 1000 projects, and I'm trying to constrain the result to just the projects with attachments.

FYI- I have ScriptRunner if that helps.

Regards - Steve Janvrin.

3 answers

3 accepted

1 vote
Answer accepted
Reece Lander _ScriptRunner - The Adaptavist Group_
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.
May 31, 2023

Hey

I'm Reece, one of the engineers on the ScriptRunner team, it's nice to hear you're considering using ScriptRunner to achieve this.

As @Florian Bonniec noted, our new HAPI scripting syntax would be ideal for this, HAPI is available in ScriptRunner 7.11.0 and later.

If I have understood the requirement correctly, you want a list of all projects where attachments are present?

The simplest script I can think of would be to run the JQL query, then collect all relevant project keys. This will be a bit slow on a large dataset, if this is something you need to do a lot, other more complex options may be better suited.

Luckily, with the power of HAPI, such a script is super simple:

 

import java.util.stream.Collectors

Issues.search('attachments is not EMPTY').stream()
.map { issue -> issue.projectObject.key }
.collect(Collectors.toSet())

HAPI processes JQL searches in batches, so you need not worry that the above script will consume a large amount of memory. I've also used Java streams to process the results, again this is to optimise memory consumption.

Hopefully HAPI can help you achieve what you need.

https://www.scriptrunnerhq.com/hapi

Cheers!

0 votes
Answer accepted
Florian Bonniec
Community Champion
May 31, 2023

Hi @Steven Janvrin 

 

JQL return issues only so you cannot use it to return Projects. What version of scriptrunner do you have ? If it' 7+ version you may create a script using HAPI to do that.

You can do a script whatever the version you use but HAPI will be easier if you are not confident with developement.

Regards

Steven Janvrin
Contributor
May 31, 2023

Thanks Florian - we'll go the ScriptRunner route.

0 votes
Answer accepted
Mohamed Benziane
Community Champion
May 31, 2023

Hi,

You can create a script with scriptrunner to achieve this. You will not be able to do it with JQL unless you willing do to it project by project in the JQL.

Steven Janvrin
Contributor
May 31, 2023

Thanks Mohamed - we'll go the ScriptRunner route.

Suggest an answer

Log in or Sign up to answer