someone can help me here below i dont want copy attachment but i want create a link of the origina attachment, so i want that sub-task have a attahcment of issue parent and dont copy attachment.
can you help me with this(it is a POST-FUNCTION on transaction)?
i think that the solution is to after this script delete a attachment on issue and add a post function at last transaction in the sub-task where copy attachment on issue and after delete on sub-task
Code to create Sub-task with a single attachment:
//Code make by Henning Tietgens
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
final SUBTASK_ISSUETYPE_NAME = "Sub-task"
if (issue.issueType.name != SUBTASK_ISSUETYPE_NAME) {
def issueFactory = ComponentAccessor.issueFactory
def constantsManager = ComponentAccessor.constantsManager
def issueManager = ComponentAccessor.issueManager
def subTaskManager = ComponentAccessor.subTaskManager
def attachmentManager = ComponentAccessor.attachmentManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def subTaskId = constantsManager.allIssueTypeObjects.find{it.name == SUBTASK_ISSUETYPE_NAME}.id
issue.attachments.eachWithIndex{att, i ->
def newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Sub-Task Attachment: " + (i + 1))
newSubTask.setDescription("Sub-Task with an Attachment")
newSubTask.setParentObject(issue)
newSubTask.setReporterId(currentUser.username)
newSubTask.setProjectObject(issue.projectObject)
newSubTask.setIssueTypeId(subTaskId)
issueManager.createIssueObject(currentUser, newSubTask)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, currentUser)
attachmentManager.copyAttachment(att, att.authorObject, newSubTask.key)
}
}
After Second POST-Fucntion to delete every Attachment in the main issue:
//
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.AttachmentManager
AttachmentManager attachmentManager = ComponentAccessor.attachmentManager
def attachments = attachmentManager.getAttachments(issue)
attachments.each {attachment ->;
attachmentManager.deleteAttachment(attachment)
}
And this code is for sub-task Transaction(POST_Function): this script copy Attahcment on the main after delete every attachment in this sub-task
//Code make by Henning Tietgens
import com.atlassian.jira.component.ComponentAccessor
final SUBTASK_ISSUETYPE_NAME = "Sub-task"
if (issue.issueType.name == SUBTASK_ISSUETYPE_NAME) {
def attachmentManager = ComponentAccessor.attachmentManager
issue.attachments.each{att ->
attachmentManager.copyAttachment(att, att.authorObject, issue.parentObject.key)
attachmentManager.deleteAttachment(att)
}
}
ok
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.