Hello,
I am using a Scriptrunner Listener in order to create several issue when an issue from a certain type is created.
I also want to copy the attachments from that trigger issue.
The code works fine when testing it in the Script Console but once I switch to building a listener (or post-function), that does not work anymore.
Here's a MWE:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.AttachmentManager
def myAttachmentManager = ComponentAccessor.getAttachmentManager()
// The trigger issue
Issue triggerIssue = event.getIssue()
List listOfIssuesToBeCreated= []
for (value in ['1', '2']) {
Issue createdIssue = Issues.create("Some project key", "Some issue type") {
setSummary("${triggerIssue .getSummary()} - request $value")
setCustomFieldValue(12011, value)
setLinks("relates to", triggerIssue.getKey() )
// setting other fields
}
listOfIssuesToBeCreated.add(createdIssue.getKey())
}
for (issueKey in listOfIssuesToBeCreated) {
log.info("Copying Attachements from ${triggerIssue.getKey()} to ${issueKey}")
Map resultOfAttachementCopy = myAttachmentManager.copyAttachments(triggerIssue, null, issueKey)
log.info(resultOfAttachementCopy)
}
The `resultOfAttachementCopy` Map is always empty.
As I said, when I execute this script in a Script Console, forcing the triggerIssue to be like triggerIssue = Issues.getByKey("My issue key") that works fine.
What am I missing?