Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Moving attachments between categories (Smart Attachments Plugin) Edited


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

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 ->"cat1") }
def targetCategory = attachmentCategories.categories.find { category ->"cat2") }

def attachment = sourceCategory.getAttachments(false).find { attachment -> attachment.filename.equalsIgnoreCase("attachment.png") }
def attachments = new ArrayList()
if (attachment != null){
facade.addAttachmentsToCategory(issue,, attachments, currentUser)

0 answers

Suggest an answer

Log in or Sign up to answer

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you