You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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))