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

Jannik Mortensen November 23, 2015

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
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2015

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?

1 vote
Phill Fox
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2015
0 votes
Jannik Mortensen November 24, 2015

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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2015

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

Jannik Mortensen November 24, 2015

Its working, Thanks!

Phill Fox
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2015

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

Suggest an answer

Log in or Sign up to answer