Create multiple tickets with one attachment from one ticket with multiple attachments

Hi all,

from our external customer we are receiving tickets with multiple attachments which are hard to process for our accounting department. In order to make their life easier, for every ticket with more than 1 attachment we want to create/copy as many tickets as there are attachments with inheriting all the fields from the source ticket and of course only one attachment.

Does somebody have a suggestion how to do it, with maybe Script Listenner for the IssueCreated event or PostFunction on the Create transition?

Is this even a good idea ? :-)


Thank you,


1 answer

1 accepted

Hello Ana. 

You can have this done in a different ways.

1. As you said, you can have it setup as a listener. Basically everytime you receive a IssueCreated event, you would inspect the attachments, and create one subtask per attachment. 

2. The second option, which I think it might be "lighter" than the listener, would be to have a postfunction on an specific transition, for example, when you switch to "In Progress" than when transitioned, creates subtasks per attachments.

A quick glance at the script would be:

def attachmentList = ComponentAccessor.attachmentManager.getAttachments(issue)
   [here you would create an issue and add the attachments]
ComponentAccessor.attachmentManage.deleteAttachmentDirectory( issue)


I by no means intend the above script to be an exact script. But that should guide you to create the script you need.

Adressing the "is this a good idea?" question. Think about it. If you are getting 1 issue creation, and if on average you have 3 attachments, you are increasing the average load of the application by 4. If you are packing a punch, that shouldn't be a issue, but it could be one if your server is small or if you have a lot of clients-customers. 

I would recommend option 2, and make it on transition, it will make that transition slow, but it would remove an unecessary load on your instance until the point at which that task creation is really needed(which is only when it is "In Progress", in my humble opinion).

If I can help you with anything else please don't hessitate to ask.

Good day and good luck!


Hi Daniel,

thank you very much for your answer, it helped a lot. I escpecially appreciate your comment to put it on transition to reduce the load. Here is my solution which works (I am sure there is some classier way to do it, but this works for me for now ;-))

import com.atlassian.jira.issue.attachment.Attachment;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.issue.IssueInputParameters

def issue = event.issue as Issue
def attachmentManager = ComponentAccessor.getAttachmentManager()
def numberAttachments = attachmentManager.getAttachments(issue).size()
def attachments = attachmentManager.getAttachments(issue)

Project project = ComponentAccessor.getProjectManager().getProjectObjByKey("TEST") 
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueService issueService = ComponentAccessor.getIssueService();
CustomField category = customFieldManager.getCustomFieldObjects(event.issue).find { == "Category"}
def value = issue.getCustomFieldValue(category)

MutableIssue newIssue = ComponentAccessor.getIssueFactory().getIssue()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();

if (numberAttachments < 2)
for (Attachment attachment : attachments){

issueInputParameters.setSummary(issue.getSummary() + " " + attachment.getFilename());
issueInputParameters.addCustomFieldValue(category.getId(), '10510');

IssueService.CreateValidationResult result = issueService.validateCreate(issue.getCreator(), issueInputParameters);
if(!result.isValid()) {
log.error("could not create issue: " + result.getErrorCollection());

newIssue = issueService.create(issue.getCreator(), result).getIssue();
attachmentManager.copyAttachment(attachment, issue.getCreator(), newIssue.getKey()); 


Hello Ana.

Thanks very much for posting your answer, I'm sure other users will find that useful. 

Would you kindly mark my answer as accepted so that users know that this question as been answered?



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


125 views 0 3
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you