Hi everybody,
For an internal project, I'm using two workflows, one for the resolution of the main ticket and one for the resolution of the many subtasks that can be created during the main ticket resolution process.
When I close a subtask, I have a screen with an attachment field allowing the user to add an attachment.
I would like to get this attachment and send it to the attachment field in the main ticket.
Actually, when a file is attached on the attachment field of the "close subtask" transition screen the attachment goes nowhere. Neither in the closed subtask and neither in the main ticket...
Does anyone got an idea on a post script function I can use to get this attachment?
I'm using script runner 5.1.6 and JIRA 7.2.0
Thanks in advance!
Regards,
Germain.
Hi Germain,
I might be able to help you here. Can you please clarify, if you want to copy just the attachment that has been added during the 'Close issue' tansition, or all attachments (including this one) that has been accumulated in the sub-task up until this point?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ivan,
Thanks a lot for your quick answer!
To clarify, I only want to copy the attachment that has been added during the 'Close issue' tansition.
I will try your code in the afternoon.
Thanks again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great, tell me if it'll solve your issue.
Please keep in mind though, that this code assumes that:
a) you add only ONE attachment during the transition
and
b) No other attachments are added as a result of this transition (either through automation or other post functions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ivan,
When I'm adding the attachment on the "close subtask" transition screen it doesn't works but if I add the attachment in the subtask before closing it, it works like a charm :)
Do you have any idea on how to get the attachment added during the close transition?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does the attachment itself get added to the subtask if you add it during the transition? Also, can you post a screenshot of your transition screen?
Cheers.
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.
Can you post a screenshot of your transition screen?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, please check if you can manually add attachments when your sub-task is in 'Closed' status. If you can't then it probably means that you don't have the permission to do so, while an issue is in that status. To check if it's indeed the case go to your workflow and check the status properties for your 'Closed' status. See if there are any properties there that might prevent you from adding attachments.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Ivan! Unfortunately I will not be able to check that immediately. I will advice you when done.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I was not allowed to modify a closed subtasks due to a properties.
Now it works!
Ivan, you are a genius :)
Many thanks that's pretty cool for my project!
Best regards!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.