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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,755 views 11 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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot