Hello,
I am trying to create a scripted post function which copies the attachment from subtask to parent, so far this is how far I've gotten, it is working OK till the attachment manager where I receive an error.
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.opensymphony.workflow.InvalidInputException import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.util.PathUtils import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.util.AttachmentUtils CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager() attachmentManager = ComponentAccessor.getAttachmentManager() pathManager = ComponentAccessor.getAttachmentPathManager() attachmentManager.getAttachments(issue).each {attachment -> filePath = PathUtils.joinPaths(pathManager.attachmentPath, issue.projectObject.key, issue.key, attachment.id.toString()) atFile = new File(filePath) File atFile = AttachmentUtils.getAttachmentFile(attachment); if (atFile.exists()) { if (atFile.canRead()) { attachmentManager.copyAttachments(atFile, attachment.filename, attachment.mimetype, attachment.author, parent_issue, [:], attachment.created) } } }
This results in error:
[scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TESTISSUE-170, actionId: 831, file: <inline script> groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.managers.DefaultAttachmentManager.copyAttachments() is applicable for argument types: (java.io.File, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.LinkedHashMap, java.sql.Timestamp) values: [/opt/jirainstallation/data/data/attachments/TESTISSUE/TESTISSUE-170/28800, ...] at Script5$_run_closure1.doCall(Script5.groovy:44) at Script5.run(Script5.groovy:23)
What could be causing this to occur ? any help is appreciated, I am on JIRA version 6.2
Community moderators have prevented the ability to post new answers.
Hi Sy,
I cannot see a copyAttachments method in the 6.2 API, so probably you have to use the createAttachment
Hi Thanos,
I tried but I get a very similar error;
kflow.ScriptWorkflowFunction] Script function failed on issue: TESTISSUE-170, actionId: 831, file: <inline script> groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.managers.DefaultAttachmentManager.createAttachment() is applicable for argument types: (java.io.File, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.LinkedHashMap, java.sql.Timestamp) values: [/opt/jirainstallation/data/data/attachments/TESTISSUE/TESTISSUE-170/28800, ...] Possible solutions: createAttachment(java.io.File, java.lang.String, java.lang.String, com.atlassian.crowd.embedded.api.User, com.atlassian.jira.issue.Issue), createAttachment(java.io.File, java.lang.String, java.lang.String, com.atlassian.crowd.embedded.api.User, org.ofbiz.core.entity.GenericValue), createAttachment(java.io.File, java.lang.String, java.lang.String, com.atlassian.crowd.embedded.api.User, com.atlassian.jira.issue.Issue, java.util.Map, java.util.Date), createAttachment(java.io.File, java.lang.String, java.lang.String, com.atlassian.crowd.embedded.api.User, org.ofbiz.core.entity.GenericValue, java.util.Map, java.util.Date), createAttachment(org.ofbiz.core.entity.GenericValue, com.atlassian.crowd.embedded.api.User, java.lang.String, java.lang.String, java.lang.Long, java.util.Map, java.util.Date) at Script3$_run_closure1.doCall(Script3.groovy:44)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can see for the API that it needs a User but you pass a String - attachment.author.
So try replace this with
attachment.authorObject.directoryUser
and then I suppose the parent_issue you have over there is of type Issue, because in the script you posted there is no parent_issue variable.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry I missed out the string variable for parent_issue, this is as
def String parent_issue = "TESTISSUE-167"
also added the directoryUser but still getting the exact same error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this should be of type Issue and not String. Use the issueManager
def issueManager = ComponentAccessor.getIssueManager() def parentIssue = issueManager.getIssueByCurrentKey("ISSUEKEY-1111")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot for your help, it worked
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.