Hello,
I wanted to check if there is a way I can create a report where it shows each issue and give the count of attachments/invoices
Example
Issue name | Number of Attachments
Issue 1 | 2
Issue 2 | 0
Issue 3 | 1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
/*
* Created 2023.
* @author Evgeniy Isaenkov
* @github https://github.com/Udjin79/SRUtils
*/
package ConsoleExamples
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.Query
AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager()
JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser) as JqlQueryParser
SearchService searchService = ComponentAccessor.getComponent(SearchService)
UserManager userManager = ComponentAccessor.getUserManager()
//Username of user, that has rights to see issues
String username = "admin"
ApplicationUser techUser = userManager.getUserByName(username) as ApplicationUser
String jql = "project = TEST"
Query query = jqlQueryParser.parseQuery(jql)
SearchResults search = searchService.search(techUser, query, PagerFilter.getUnlimitedFilter())
List issues = search.results
String report = ""
issues.each { Issue issue ->
List<Attachment> attachments = attachmentManager.getAttachments(issue)
report += "Issue: ${issue.key}. Count: ${attachments ? attachments.size() : 0}\n"
}
log.warn(report)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, @Joseph Chung Yin
I forgot to tell, that with scriptrunner can be made scripted field, which can count attachments. Your comment reminded me about this opportunity.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Domnic -
I agreed with Evgeniy's response. However if you have Scriptrunner for Jira add-on, then you can take a look at the following reference page for this add-on (Data Center/Server) using the build-in JQL function
https://docs.adaptavist.com/sr4js/latest/features/jql-functions/included-jql-functions/attachments
This will be a great starting point and you can create your own JQL functions -
https://docs.adaptavist.com/sr4js/latest/features/jql-functions/custom-jql-functions
Hopefully, this will get you going. Please note that the above recommendation allows you to gather the data first, then you will need to go further to develop your reporting needs.
Hope this helps.
Best, Joseph Chung Yin
Jira/JSM Functional Lead, Global Technology Applications Team
Viasat Inc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Domnic
if you are option to solutions from the Atlassian Marketplace, this would be trivial to do using the app that my team and I are working on, JXL for Jira.
JXL is a full-fledged spreadsheet/table view for your issues that allows viewing, inline-editing, sorting, and filtering by all your issue fields, much like you’d do in e.g. Excel or Google Sheets. It also comes with a number of so-called "smart columns" that aren’t natively available, including the number of attachments (along with several other attachment-related smart columns).
This is how it looks in action:
As you can see above, you can easily sort and filter by the number of attachments, and also use it across JXL's many advanced features, such as support for (configurable) issue hierarchies, issue grouping by any issue field(s), sum-ups, or conditional formatting. This all "just works"; there's no scripting whatsoever required.
Since you've tagged your question for Jira Server: As you may have heard, app sales have ended for Jira Server. Are you planning to migrate to Data Center or Cloud? I'd strongly recommend that. If you need some more time, JXL is perfectly compatible with Jira Server; it's just that we need to generate a license for you. If the above looks interesting, just let me know, and I'll happily start a free trial for you.
Any questions just let me know,
Best,
Hannes
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.