How can I clone (or add) attachements with new CreateAttachmentParamsBean ?

Hello,

I'm trying to clone attachments from issue to newIssue with this function.

I'm in Jira 6.2

But I receive an error.

Function

CopyAttach = { Issue issue, MutableIssue newIssue ->
attachmentManager = componentManager.getAttachmentManager()
pathManager = componentManager.getAttachmentPathManager()
attachmentManager.getAttachments(issue).each {attachment ->
filePath = PathUtils.joinPaths(pathManager.attachmentPath, issue.projectObject.key, issue.key, attachment.id.toString())
log.debug("*** CopyIssue :: filePath = $filePath")
atFile = new File(filePath)
log.debug("*** CopyIssue :: New : OK")
if (atFile.exists()) {
try {
if (atFile.canRead()) {
log.debug("*** CopyIssue :: read : OK")
CreateAttachmentParamsBean bean = new CreateAttachmentParamsBean(atFile,attachment.filename,attachment.mimetype, attachment.author, newIssue , false , false, null, attachment.created, true)
attachmentManager.createAttachment(bean)
log.debug("*** CopyIssue :: attachment : OK")
}
}
catch (SecurityException se) {
log.debug("*** CopyIssue :: Could not read attachment file. Not copying. (${se.message})")
}
}
else {
log.debug("*** CopyIssue :: Attachment file does not exist where it should. Not copying.")
}
}
}

Error

2014-07-07 17:13:03,842 http-bio-8080-exec-19 ERROR FAB055 1033x8965x1 1y2tkcp 172.24.21.108 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean(java.io.File, java.lang.String, java.lang.String, java.lang.String, com.atlassian.jira.issue.IssueImpl, java.lang.Boolean, java.lang.Boolean, java.util.LinkedHashMap, java.sql.Timestamp, java.lang.Boolean)
2014-07-07 17:13:03,842 http-bio-8080-exec-19 ERROR FAB055 1033x8965x1 1y2tkcp 172.24.21.108 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Script post-function failed on DMI-8882: \\jira\Jira\AppData\Scripts\CopyIssue.groovy
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean(java.io.File, java.lang.String, java.lang.String, java.lang.String, com.atlassian.jira.issue.IssueImpl, java.lang.Boolean, java.lang.Boolean, java.util.LinkedHashMap, java.sql.Timestamp, java.lang.Boolean)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:102)
at com.onresolve.jira.groovy.GroovyRunner.run(GroovyRunner.java:62)
at com.onresolve.jira.groovy.GroovyFunctionPlugin.execute(GroovyFunctionPlugin.java:38)
at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050)
at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446)
at com.opensymphony.workflow.AbstractWorkflow.doAction(AbstractWorkflow.java:564)
at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowActionInsideTxn(OSWorkflowManager.java:957)
at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowAction(OSWorkflowManager.java:912)
at com.atlassian.jira.bc.issue.DefaultIssueService.transition(DefaultIssueService.java:450)

What is missing ?

Thx

1 answer

1 accepted

This widget could not be displayed.

In the constructor of CreateAttachmentParamsBean you are using attachment.author to get the user. That method returns the user name as String, but the constructor expects an ApplicationUser. Use attachment.authorObject instead.

Great, Thank you.

br,

Michel Katz

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

526 views 3 19
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