How to show attachments in Issue Navigator

Adolfo Casari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 13, 2014

Is there any way to show in a column in Issue Navigator the names of the attachments for an issue?

Thanks in advance,

3 answers

1 accepted

11 votes
Answer accepted
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 13, 2014

Currently not possible - https://jira.atlassian.com/browse/JRA-4737

However you might be able to implement that using custom scripted field (Script Runner) which will display attachment names for an issue and you'll be able to add it as a column in the issue navigator.

Here's a sample groovy code for the field:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys

def attachments = ComponentAccessor.getAttachmentManager().getAttachments(issue)
def baseUrl = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)

attachments.collect {
    '<a href="' + baseUrl + '/secure/attachment/'+ it.id +'/'+
        URLEncoder.encode(it.filename, "UTF-8") +'">' + it.filename + '</a>'
}.join("<br>")

(Modified by @Jamie Echlin [Adaptavist] to support attachment filenames containing spaces Nov 2016).

Use script field config: Template: HTML.

 

Adolfo Casari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2014

Thanks for sharing the script.

Renee Lyons November 18, 2016

Thank you, @Jamie Echlin [Adaptavist]!!

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 18, 2016

You're welcome, and thanks to @Boris Georgiev [Botron] too wink

Oleksandr Chalyi November 27, 2018

Thank you, that's just what we need!

0 votes
Andrews September 3, 2020

Hi,

I want to display sum of two number fields to third number field.

ex: 1 Support Count CRM(2.0) = 510

      2 Support Count CRM(Old) = 10

      3 Support Count CRM(New) = 4

 

Calculate the sum of 2 custom fields (2+3) to the third custom field (1)

 

  • 1= 2+3 
  • 510 = 10+4
  • 524
Sunny September 3, 2020

Hello Andrews,

Create a scripted field and insert this script  below, and add the scripted field to the view screen.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager();

//your first field
CustomField custNum = customFieldManager.getCustomFieldObjectByName("numfield1");
def custNumValue = issue.getCustomFieldValue(custNum);

//your second field
CustomField anotherCustNum = customFieldManager.getCustomFieldObjectByName("numfield2");
def anotherCustNumValue = issue.getCustomFieldValue(anotherCustNum);

//your third field
CustomField anotherCustNum2 = customFieldManager.getCustomFieldObjectByName("numfield3");
def anotherCustNumValue2 = issue.getCustomFieldValue(anotherCustNum2);

 

if(custNumValue !=null && anotherCustNumValue != null && anotherCustNumValue2 != null) {
def finalValue = custNumValue+anotherCustNumValue+anotherCustNumValue2;
return finalValue;
}

Thanks!!

Like Mechee likes this
0 votes
Johan Geens September 12, 2017

This is better, it gives you clickable file names (to download them) and also lists multiple attached file names:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys

def attachments = ComponentAccessor.getAttachmentManager().getAttachments(issue)
def baseUrl = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)

attachments.collect {
'<a href="' + baseUrl + '/secure/attachment/'+ it.id +'/'+
URLEncoder.encode(it.filename, "UTF-8") + '"' + '>' + it.filename + '</a>' + '<br>'
}.join('<br>')
Dan27 April 24, 2018

Hi, @Johan Geens

I've got this error while trying this script:

2018-04-24 08:33:30,515 ERROR [customfield.GroovyCustomField]: *************************************************************************************
2018-04-24 08:33:30,515 ERROR [customfield.GroovyCustomField]: Script field failed on issue: WBL-45930, field: Attachments(Script)
groovy.lang.MissingMethodException: No signature of method: com.onresolve.scriptrunner.customfield.GroovyCustomField$_getValueFromIssue_closure1.doCall() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [Attachments, []]
Possible solutions: doCall(java.lang.Object), findAll(), findAll()
 at Script1435.run(Script1435.groovy:43)

Can you help me to figure it out?
Thanks

 

r_k January 30, 2019

Use this groovy code in Script Field it works!! But it need to create new custom field.

Sunny January 17, 2020

Hello,

I see null, Is that because of the file path?

C:\Users\home\Atlassian\Application Data\Jira\data\attachments

this my path for attachments. script seems to be good but see null when I preview.

 

Thanks in advance.

Suggest an answer

Log in or Sign up to answer