Hello everyone! I'm trying to copy an attachment from a screen ,
Who is associate to the closure of a subtask .
I succeeded to do it with comment :
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def originalComment = transientVars.comment as String
def comments = originalComment
if (comments!=null)
{
commentManager.create(parentIssue, user, comments, false)
}
I'm trying to do an equivalent with the attachement ( copyAttachments(Issue issue, ApplicationUser author, String newIssueKey)
) but
transientVars.attachment
Does not seem to exist
How am I supposed to do ?
Hi Sergio,
Based on your description, the attachment added during the 'Close issue' transition is always the last one (unless you have any post functions/automation that adds more attachments after that), the code to copy it to the parent issue is as follows:
import com.atlassian.jira.component.ComponentAccessor
def attMgr = ComponentAccessor.getAttachmentManager()
def attachments = attMgr.getAttachments(issue)
def lastAtt = attachments[0]
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
if (attachments.size() > 1){
for (int i = 1; i < attachments.size(); i++){
if (lastAtt.getCreated().getTime() < attachments[i].getCreated().getTime()){
lastAtt = attachments[i]
}
}
}
attMgr.copyAttachment(lastAtt, currentUser, issue.getParentObject().getKey())
Also, make sure that you place this post function AFTER the "Re-index an issue to keep indexes in sync with the database" post function
Hi Sergio,
I would like to do the exact same thing but have no idea on how to manage that.
Hope someone could help :)
Best regards,
Germain.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am also trying to copy the last attachment during a post function by groovy. You did it?
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.