Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Copy attachments from parent to subtasks during the creation transition

Camille Lecerf
Contributor
September 10, 2018

Hi,

I am using a Scriptrunner post-function to create subtasks when I create an issue.
I can copy fields from parent issue to sub-tasks.
How could I do to copy the attachments to the subtasks please ?
Maybe in the additional issue actions ?

Or even better : a field in the subtask pointing on the parent issue's attachments

Thanks & regards,

Camille

2018-09-10 11_48_15-Update Workflow Function Parameters.png

 

2 answers

0 votes
Mehmet Gökhan Çöplüoğlu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 17, 2018

Hi,

I used this script for create same issue an another project and copy attachment to new created issue. You should add "Custon Script Postfunction" on create transition. 



MutableIssue missue = issue
//Issue missue = ComponentAccessor.getIssueManager().getIssueByKeyIgnoreCase("xxx-13957")
IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
IssueInputParameters issueInputParametersIdari = issueService.newIssueInputParameters()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager()
AttachmentPathManager pathManager = ComponentAccessor.getAttachmentPathManager()

if(missue.getIssueType().getName() == "Task"){
if("Task" in missue.componentObjects*.name){
log.debug("true")
issueInputParametersIdari.setProjectId(10410L).setSummary(missue.getSummary()).setDescription(missue.getDescription()).setIssueTypeId("13500").setPriorityId(missue.getPriority().getId()).setComponentIds(20987L).setReporterId(missue.getReporterId().toString()).setAssigneeId(missue.getAssigneeId().toString())
IssueService.CreateValidationResult createValidationResultIdari = issueService.validateCreate(user, issueInputParametersIdari)

if (createValidationResultIdari.isValid()) {

def issueResult = issueService.create(user, createValidationResultIdari)
log.debug("issue created")
log.debug("issuekey : "+issueResult.getIssue())//new created issue
Issue issueIdari= issueResult.getIssue() //new created issue

log.debug("attachments : "+attachmentManager.getAttachments(missue))
log.debug("attachmentPath : "+pathManager.attachmentPath)

attachmentManager.getAttachments(missue).each {attachment ->
log.debug("key : "+ attachment.getId())
File rootDir = new File(pathManager.attachmentPath)
File filePath = FileAttachments.getAttachmentDirectoryForIssue(rootDir, missue.projectObject.getKey(), missue.getKey())
String filePaths = filePath.toString()
filePaths=filePaths+"//"+attachment.getId()
File atFile = new File(filePaths)

if (atFile.exists()) {

attachmentManager.createAttachmentCopySourceFile(atFile, attachment.filename, attachment.mimetype, attachment.author, issueIdari, [:], attachment.created) log.debug("atachs created!!!!")
}

}


}else{ log.debug("issue cant create") }


}
}

 You need to find subtasks of your parent issue. Then should use subtasks instead of issueIdari.

0 votes
Mohamed Benziane
Community Champion
September 10, 2018

Hello Camille,

Can you take a look at this page. It seems that the code put by a community champion works well.

 You will need to pull this script in a postfunction i think

Hope this helps

Regards

Camille Lecerf
Contributor
September 10, 2018

Hi Mohamed,

Thank you for your help.
This code copies the attachment from the subtask to the parent issue.
I would like to copy the attachment from the parent issue to the subtask.
I am not good enough at coding to adapt it... Could someone help me on it please ?

Regards,

Camille

Suggest an answer

Log in or Sign up to answer