Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to copy the contents of an Apwide File Field to Jira's general attachment field Edited

In our Jira Server we work with the apps Apwide File Field, Automation for Jira and ScriptRunner.

I want to copy the contents of an Apwide File Field (customFieldId=14795) to Jira's general attachment field.

I think a solution with Scriptrunner and Groovy will work.

I just can't figure out how to get the correct content of the groovy script in my use case. Can anyone help me with that?

I want to copy the contents of an Apwide File Field (customFieldId=14795) to Jira's general attachment field :-)


Marco Brundel

2 answers

2 accepted

Hi @Marco Brundel

For your requirement, you could try using a Listener.

The IssueCreate event / IssueUpdated event can be used to copy the attachment from the Apwide File Field to the Attachment field either during the creation of the Issue or when the Issue is being updated.

Below is a print screen of the Listener configuration:-


Below is a working sample code for your reference:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean

import java.text.SimpleDateFormat

def issue = event.issue as MutableIssue

def customFieldManager = ComponentAccessor.customFieldManager
def attachmentManager = ComponentAccessor.attachmentManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def appwide = customFieldManager.getCustomFieldObjectsByName("Appwide Attachment")[0]
def appwideValue = appwide.getValue(issue).toString().split(",") as List<String>

//The path where the apwide attachments are stored
def folderPath = "/media/ram/Linux_Disk_Space/atlassian/application-data/jira8/data/attachments/00_apwide_file_field_files"

def formatYear = new SimpleDateFormat("yyyy")
def formatCurrentDate = new SimpleDateFormat("yyyy-MM-dd")
def currentYear = formatYear.format(new Date())
def currentDate = formatCurrentDate.format(new Date())

def latestFile = "${folderPath}/${currentYear}/${currentDate}/${appwideValue.last()}"
def sourceFile = new File(latestFile)

def attachmentParams = new CreateAttachmentParamsBean(sourceFile,,null,loggedInUser,issue,null,false,null,new Date(),true)

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below are some test print screens:-

1) When the Appwide attachment is added, it is automatically added to Jira's attachment, as well as shown in the image below:-


2) Although the attachment displays as the Actual file name added when it is stored in the Folder, it will display a timestamp as shown in the image below:-


which is why the Jira attachment appears to be so.

3) However, in the Jira attachments folder, it displays as a regular attachment file as shown below:-


I hope this helps to answer your question. :)

Thank you and Kind Regards,


Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Thank you, with your tips I got it working. 


0 votes
Answer accepted

Thanks for your question @Marco Brundel and for your great support @Ram Kumar Aravindakshan _Adaptavist_ 

Additional examples of integration between File Field and ScriptRunner:

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

🤺 Atlympic Event: Partnerships

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

124 views 1 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you