How do i make a field that counts the number of attachments?

Just upgrade to JIRA 7.0.2 and my old custom field is gone, which did the above.


Looked at scriptrunner, but couldn't get it working. Any ideas?

3 answers

1 accepted

2 votes

Script runner can do it, and it's quite easy to do as well - I've got a feeling it's a one-line scripted field.

What have you tried there?

Tried the example from scriptrunner, as Phill mentions. but it doesnt work.

I see now that it has been superseeded by hasAttachments. jql function. But it doesnt make any sense to me with my lack of programmingskills. I can see how it can be used to make a query but not to pull the actual count in a custom field.


Do you have any examples?


Thanks for taking your time.

As Phill may be at lunch, the script on that page needs updating as it was written for JIRA 6 @Thanos Batagiannis [Adaptavist] gave us a new one: import com.atlassian.jira.component.ComponentAccessor def attachmentManager = ComponentAccessor.getAttachmentManager() def numberAttachments = attachmentManager.getAttachments(issue).size() // use the following instead for number of PDFs //def numberAttachments = attachmentManager.getAttachments(issue).findAll {a -> // a.filename.toLowerCase().endsWith(".pdf") //}.size() return numberAttachments ? numberAttachments as Double : null

Its working, Thanks!

Thanks @Nic Brough [Adaptavist] for posting the answer whilst I was at lunch.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

243 views 1 18
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