"Clones an issue and links" does not clone attachments

Atlassian October 30, 2014

The built in ScriptRunner Script "Clones an issue and links" doesn't clone the attachments of the original Issue.

 

I'm using the following "Additional issue actions" to dynamically set the "Target Project" according to a predefined custom field:

import com.atlassian.jira.component.ComponentAccessor
issue.setProjectObject(ComponentAccessor.getProjectManager().getProjectObjByName(sourceIssue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Linked Project")).getValue()))
issue.setSecurityLevelId()
issue.setAssigneeId()
checkLink = {link -> false}
checkAttachment = {attachment -> true}

Setting the Target Project works fine, only Problem is that attachments won't be cloned.

3 answers

0 votes
Atlassian November 7, 2014

I was able to hunt down the root cause myself:

The project in Question has a changed project key. As documented the attachments will still be stored using the original project key.

This part in your "copyAttachments" function is wrong:

def filePath = PathUtils.joinPaths(pathManager.attachmentPath, issue.projectObject.key, issue.key, attachment.id.toString())

It should be refering to "originalKey" for both project and issue key.

 

Can this please be fixed?

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 8, 2014

Thanks for that, I created https://jamieechlin.atlassian.net/browse/GRV-556 - please watch for updates.

Matt C July 22, 2015

Hi Jamie Have you had a chance to look at this one? I just realised that is why our attachments have stopped copying on a clone action

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.
July 22, 2015

I have not... but it seems easy enough to solve. I will try to get to it, but no plans for a new release for a few weeks.

Matt C September 21, 2015

Hi Jamie, Did this fix make it into 4.1 in the end? Cheers

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.
September 24, 2015

Sorry, it did not. But I've made and tested the changes now and it will go into the next version: https://jamieechlin.atlassian.net/browse/GRV-806. Will release next week.

DavidS September 24, 2015

Fantastic! Thanks for that

0 votes
Atlassian October 31, 2014

Thanks for your fast reply, I did some more testing and was able to gather the following further info:

  • The issue is not caused by the issue.setSecurityLevelId() and issue.setAssigneeId() statements - these do in fact work and set these Fields to NULL.
  • The issue is not caused by my issue.setProjectObject() Statement
  • Cloning of Attachments does work in a different (Test) Project using the same Workflow(functions).
  • The issue seems to be related to the originating project beeing a "JIRA Service Desk" - There are plenty of small changes to the way Issues work in there.
  • I get the following Message in my logs when the Problem occurs. 

    WARN /secure/CommentAssignIssue.jspa [jira.workflow.postfunctions.CloneIssue] Attachment file does not exist where it should. Not copying.

Maybe this is related to more restrictive Permissions in effect for the Service Desk Project?

 

0 votes
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.
October 30, 2014

Does it work if you don't change the project?

Have you checked the logs, it looks like the following lines of your code are not valid:

issue.setSecurityLevelId()
issue.setAssigneeId()

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events