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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,700
Community Members
 
Community Events
176
Community Groups

Moving attachments between categories (Smart Attachments Plugin)

Edited

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))  

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events