Hi,
I am trying to move Attachments from one category into another one, using ScriptRunner for Jira.
As soon as an attachment is moved, I want to check if the attachment is correctly stored in the new attachment category.
The problem I am facing, is that the attachments get moved correctly, but the attachment List in the new category is empty until the script is finished.
If I check the attachment category List again, all attachments are display correctly.
Can someone tell me where my mistake is?
This is my code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.util.UserManager
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.stiltsoft.jira.attachcategory.facade.SmartAttachmentsFacade
import com.stiltsoft.jira.attachcategory.facade.entity.issue.AttachmentCategories
import com.atlassian.jira.event.type.EventDispatchOption// Initializing the app components
@WithPlugin("com.stiltsoft.jira.smart-attachments")
SmartAttachmentsFacade facade = ScriptRunnerImpl.getPluginComponent(SmartAttachmentsFacade)
UserManager userManager = ComponentAccessor.getUserManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issue = issueManager.getIssueObject("SI-109639")AttachmentCategories attachmentCategories = facade.getAttachmentCategories(issue)
def sourceCategory = attachmentCategories.categories.find { category -> category.name.equalsIgnoreCase("cat1") }
def targetCategory = attachmentCategories.categories.find { category -> category.name.equalsIgnoreCase("cat2") }
def attachment = sourceCategory.getAttachments(false).find { attachment -> attachment.filename.equalsIgnoreCase("attachment.png") }
def attachments = new ArrayList()
if (attachment != null){
attachments.add(attachment)
}
facade.addAttachmentsToCategory(issue, targetCategory.id, attachments, currentUser)
log.warn(targetCategory.getAttachments(false))