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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

991 views 3 12
Read article

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