Check out our new apps for Jira Cloud and start free trial.
Skip to end of metadata
Go to start of metadata

This example illustrates the way to move attachments from one category to another within the same issue.

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

// 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 = userManager.getUserByName("admin")

// Specifying the issue which contains files for moving
def issue = issueManager.getIssueObject("ONE-1")

AttachmentCategories attachmentCategories = facade.getAttachmentCategories(issue)

// Specifying the source and target categories for moving attachments
def categoryDocuments = attachmentCategories.categories.find { category -> category.name.equalsIgnoreCase("Documents") }
def categoryScreenshots = attachmentCategories.categories.find { category -> category.name.equalsIgnoreCase("Screenshots") }

// Specifying the attachment name
def attachments = new ArrayList()
def attachment = categoryDocuments.getAttachments(false).find { attachment -> attachment.filename.equalsIgnoreCase("image.png") }
attachments.add(attachment)

facade.addAttachmentsToCategory(issue, categoryScreenshots.id, attachments, currentUser)
  • No labels