Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • Community
  • Q&A
  • Jira
  • Questions
  • How to copy attachments to linked issue but not replacing existing attachements, just adding new?

JMCF Time in Status not uploading

paula.magalhaes
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 21, 2023

Hello,

I have added a Jira Misc Custom Field for Time in Status so that I can see in my issue screen how much time the issue has been in a specific status. Initially when I first added it worked just like I wanted, but it stoped updating as time passed. The time displayed there is the same it was when I first added it, one week ago. I´ve looked every where and can´t find a good answer on what´s happening or how to fix it, can anyone help me?

In addition, I was looking for something which I could also see the average time all issues have spent on that status. I know there´s a plug in that will show this, but I was wondering if there are any add-ons or plug ins that will show both the time a specific issue has been on that status on its screen and a report with average times as well. I have found plug ins for both separetly but none that will do both.

Thanks in advance for the help

1 answer

1 accepted

0 votes
Answer accepted
David Fischer
Community Champion
October 8, 2018

Hi Bojana,

the problem is that, since you are copying attachments between issues, they become different attachments on the destination issue, so it's not really easy to identify "new" attachments from already-copied ones. You could consider identically named attachments as being the same, but that's not exactly always right. And since Jira doesn't store attachment metadata like an MD5 that could uniquely identify attachments across issues, identifying copied attachments is difficult.

Of course, you could use the "Add field values" option, but then all attachments would be copied again, not just new attachments.

If you believe that comparing attachment names and sizes would be enough to avoid duplicates, then I could provide you with a simple Groovy script to be run in a Scripted (Groovy) post-function. Let me know.

David

Bojana Vasic
Contributor
October 11, 2018

Hi @David Fischer

Thanks a lot for your answer! I would appreciate if you could share a script so I can test the solution.

Many thanks!

David Fischer
Community Champion
October 11, 2018

Here's a script that would work as a Scripted (Groovy) post-function on your reopen transition of issue B. It will copy new attachments from issues linked to the current B issue through the "blocks" link type (adjust as needed) to the current B issue.

import com.atlassian.jira.issue.attachment.Attachment

//the current issue's existing attachments
def attachments = issue.get("attachment")

//iterate over the issues linked to the current issue through the "blocks" link type - change the link type as needed
for (Issue linkedIssue : issue.getLinkedIssues("blocks")) {
//add new attachments from linked issue
def linkedAttachments = linkedIssue.get("attachment")
for (Attachment linkedAttachment : linkedAttachments) {
//test if this attachment from the linked issue already exists on the current issue
if (!attachments.find{it.filename == linkedAttachment.filename && it.filesize == linkedAttachment.filesize && it.mimetype == linkedAttachment.mimetype})
//this attachment is new, copy it to the current issue
ComponentAccessor.attachmentManager.copyAttachment(linkedAttachment, currentUser, issue.key)
}
}
Bojana Vasic
Contributor
October 11, 2018

Thanks again, will test.

Bojana Vasic
Contributor
October 16, 2018

Hi again @David Fischer,

Will this keep attachements which already exist in B issue (which are not originally from A issue), or will those be replaced once attachements are compared and copied from A to B on the reopening? I need to keep all originally attached files in B not replacing them with attachements from A, and adding just the new ones from A but not replacing all from B as said...

Thanks again! :)

David Fischer
Community Champion
October 16, 2018

It will only add new attachments, never remove any (even those that are removed from issue A).

Swarna Radha
Contributor
August 20, 2019

Hi, 

I am getting errors in the script as from for (Issue linkedIssue : issue.getLinkedIssues("blocks")) { till the end of the code

 

import com.atlassian.jira.issue.attachment.Attachment

//the current issue's existing attachments
def attachments = issue.get("attachment")

//iterate over the issues linked to the current issue through the "blocks" link type - change the link type as needed
for (Issue linkedIssue : issue.getLinkedIssues("blocks")) {
//add new attachments from linked issue
def linkedAttachments = linkedIssue.get("attachment")
for (Attachment linkedAttachment : linkedAttachments) {
//test if this attachment from the linked issue already exists on the current issue
if (!attachments.find{it.filename == linkedAttachment.filename && it.filesize == linkedAttachment.filesize && it.mimetype == linkedAttachment.mimetype})
//this attachment is new, copy it to the current issue
ComponentAccessor.attachmentManager.copyAttachment(linkedAttachment, currentUser, issue.key)
}
}Capture 2.PNG
David Fischer
Community Champion
August 21, 2019

Hi,

The code I shared is for JMWE, not ScriptRunner. That is why it is failing in ScriptRunner. 

Regards

David

Swarna Radha
Contributor
August 21, 2019

Hi,

Is there any code for script runner?

Thanks,

Swarna

Suggest an answer

Log in or Sign up to answer