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
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.