"Clones an issue and links" does not clone attachments

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 vote

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()

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?

 

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?

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

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

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.

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

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.

Fantastic! Thanks for that

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

179 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you